ServiceWeaver / weaver-kube

Run Service Weaver applications on vanilla Kubernetes.
Apache License 2.0
61 stars 19 forks source link

Added basic plugin system to customize telemetry. #86

Closed mwhittaker closed 11 months ago

mwhittaker commented 11 months ago

This PR introduces a very basic plugin system that allows developers to customize how weaver-kube manages logs, metrics, and traces. For example, consider the following foo/main.go:

// This is file foo/main.go.
package main

import ...

func main() {
    plugins := tool.Plugins{
        HandleLogEntry: func(context.Context, *protos.LogEntry) error {
            ...
        },
        HandleTraceSpans: func(context.Context, []trace.ReadOnlySpan) error {
            ...
        },
        HandleMetrics: func(context.Context, []*metrics.MetricSnapshot) error {
            ...
        },
    }
    tool.Run("foo", plugins)
}

We can build this file into an executable foo that behaves the same as weaver-kube, but uses the provided plugins:

$ foo --help
Deploy and manage Service Weaver programs.

Usage:
  foo <command> ...

Available Commands:
  deploy       Deploy a Service Weaver app
  help         Print help for a sub-command
  version      Show foo version

Flags:
  -h, --help   Print this help message.

Use "foo help <command>" for more information about a command.

See https://github.com/mwhittaker/jeagar for a complete example.

In the long term, we'll replace this basic plugin mechanism with something more general. This PR allows customers to onboard to Service Weaver in the short term.