mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-04 01:09:36 +02:00
zero/connect: add telemetry request command (#5131)
* zero/connect: add telemetry request command * rm relabeling
This commit is contained in:
parent
2b1dcf7355
commit
e12532ba52
5 changed files with 376 additions and 28 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue