zero/connect: add telemetry request command (#5131)

* zero/connect: add telemetry request command

* rm relabeling
This commit is contained in:
Denis Mishin 2024-06-10 22:54:02 -04:00 committed by GitHub
parent 2b1dcf7355
commit e12532ba52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 376 additions and 28 deletions

View file

@ -1,12 +1,17 @@
package mux
import "context"
import (
"context"
"github.com/pomerium/pomerium/pkg/zero/connect"
)
type config struct {
onConnected func(ctx context.Context)
onDisconnected func(ctx context.Context)
onBundleUpdated func(ctx context.Context, key string)
onBootstrapConfigUpdated func(ctx context.Context)
onTelemetryRequested func(ctx context.Context, req *connect.TelemetryRequest)
}
// WatchOption allows to specify callbacks for various events
@ -40,6 +45,12 @@ func WithOnBootstrapConfigUpdated(onBootstrapConfigUpdated func(context.Context)
}
}
func WithOnTelemetryRequested(onTelemetryRequested func(context.Context, *connect.TelemetryRequest)) WatchOption {
return func(cfg *config) {
cfg.onTelemetryRequested = onTelemetryRequested
}
}
func newConfig(opts ...WatchOption) *config {
cfg := &config{}
for _, opt := range []WatchOption{
@ -47,6 +58,7 @@ func newConfig(opts ...WatchOption) *config {
WithOnDisconnected(func(_ context.Context) {}),
WithOnBundleUpdated(func(_ context.Context, _ string) {}),
WithOnBootstrapConfigUpdated(func(_ context.Context) {}),
WithOnTelemetryRequested(func(_ context.Context, _ *connect.TelemetryRequest) {}),
} {
opt(cfg)
}

View file

@ -48,6 +48,8 @@ func dispatch(ctx context.Context, cfg *config, msg message) error {
cfg.onBundleUpdated(ctx, "config")
case *connect.Message_BootstrapConfigUpdated:
cfg.onBootstrapConfigUpdated(ctx)
case *connect.Message_TelemetryRequest:
cfg.onTelemetryRequested(ctx, msg.Message.GetTelemetryRequest())
default:
return fmt.Errorf("unknown message type")
}