mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-16 02:27:40 +02:00
zero/telemetry: internal envoy stats scraper and metrics producer (#5136)
This commit is contained in:
parent
c3534df885
commit
c1dec06afa
19 changed files with 667 additions and 301 deletions
|
@ -2,18 +2,17 @@ package controller
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/internal/retry"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
)
|
||||
|
||||
type leaser struct {
|
||||
client databroker.DataBrokerServiceClient
|
||||
funcs []DbcFunc
|
||||
funcs []func(context.Context, databroker.DataBrokerServiceClient) error
|
||||
}
|
||||
|
||||
// GetDataBrokerServiceClient implements the databroker.LeaseHandler interface.
|
||||
|
@ -23,20 +22,18 @@ func (c *leaser) GetDataBrokerServiceClient() databroker.DataBrokerServiceClient
|
|||
|
||||
// RunLeased implements the databroker.LeaseHandler interface.
|
||||
func (c *leaser) RunLeased(ctx context.Context) error {
|
||||
log.Debug(ctx).Msg("leaser: running leased functions")
|
||||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for _, fn := range c.funcs {
|
||||
eg.Go(func() error {
|
||||
return retry.WithBackoff(ctx, func(ctx context.Context) error { return fn(ctx, c.client) })
|
||||
})
|
||||
fn := fn
|
||||
eg.Go(func() error { return fn(ctx, c.client) })
|
||||
}
|
||||
err := eg.Wait()
|
||||
log.Debug(ctx).Err(err).Msg("leaser: done running leased functions")
|
||||
return err
|
||||
}
|
||||
|
||||
func WithLease(funcs ...DbcFunc) DbcFunc {
|
||||
func WithLease(
|
||||
funcs ...func(context.Context, databroker.DataBrokerServiceClient) error,
|
||||
) func(context.Context, databroker.DataBrokerServiceClient) error {
|
||||
return func(ctx context.Context, client databroker.DataBrokerServiceClient) error {
|
||||
srv := &leaser{
|
||||
client: client,
|
||||
|
@ -46,3 +43,18 @@ func WithLease(funcs ...DbcFunc) DbcFunc {
|
|||
return leaser.Run(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type LeaseStatus struct {
|
||||
v atomic.Bool
|
||||
}
|
||||
|
||||
func (w *LeaseStatus) HasLease() bool {
|
||||
return w.v.Load()
|
||||
}
|
||||
|
||||
func (w *LeaseStatus) MonitorLease(ctx context.Context, _ databroker.DataBrokerServiceClient) error {
|
||||
w.v.Store(true)
|
||||
<-ctx.Done()
|
||||
w.v.Store(false)
|
||||
return ctx.Err()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue