Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic plugin system to customize telemetry. #86

Merged
merged 2 commits into from
Nov 6, 2023
Merged

Conversation

mwhittaker
Copy link
Member

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.

@mwhittaker mwhittaker self-assigned this Oct 25, 2023
Copy link
Collaborator

@rgrandl rgrandl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

return fmt.Errorf("Babysitter.Serve: listen on port %d: %w", prometheusPort, err)
group, ctx := errgroup.WithContext(b.ctx)

if b.opts.HandleMetrics == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logs: we print them with pretty printer if there is no custom way to manipulate them
Traces: we don't do anything if no custom way to manipulate them
Metrics: if no custom way to manipulate them, we export them to an http server that we will be running (in prometheus format)

Could we:

  1. Create an examples or plugins directory under weaver-kube and add the jaeger example?
  2. Also add an example for metrics integration with Prometheus in the same directory? The http server code that is here can go there. I think we shouldn't do anything by default (same as for traces).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to not export metrics by default. I'll add examples in a future PR!

"github.com/ServiceWeaver/weaver-kube/internal/impl"
"github.com/ServiceWeaver/weaver/runtime/tool"
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Base automatically changed from whats_up_docker to main November 6, 2023 18:22
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:

```shell
$ 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.
Copy link
Member Author

@mwhittaker mwhittaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Robert!

"github.com/ServiceWeaver/weaver-kube/internal/impl"
"github.com/ServiceWeaver/weaver/runtime/tool"
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return fmt.Errorf("Babysitter.Serve: listen on port %d: %w", prometheusPort, err)
group, ctx := errgroup.WithContext(b.ctx)

if b.opts.HandleMetrics == nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to not export metrics by default. I'll add examples in a future PR!

@mwhittaker mwhittaker merged commit d79c670 into main Nov 6, 2023
10 checks passed
@mwhittaker mwhittaker deleted the plugins branch November 6, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants