mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 18:07:17 +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
|
@ -6,14 +6,16 @@ import (
|
|||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/slices"
|
||||
)
|
||||
|
||||
type producer struct {
|
||||
type Producer struct {
|
||||
scope instrumentation.Scope
|
||||
clientProvider func() (databroker.DataBrokerServiceClient, error)
|
||||
}
|
||||
|
@ -21,14 +23,14 @@ type producer struct {
|
|||
func NewProducer(
|
||||
scope instrumentation.Scope,
|
||||
clientProvider func() (databroker.DataBrokerServiceClient, error),
|
||||
) metric.Producer {
|
||||
return &producer{
|
||||
) *Producer {
|
||||
return &Producer{
|
||||
clientProvider: clientProvider,
|
||||
scope: scope,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *producer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, error) {
|
||||
func (p *Producer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, error) {
|
||||
client, err := p.clientProvider()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting client: %w", err)
|
||||
|
@ -43,6 +45,9 @@ func (p *producer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, erro
|
|||
eg.Go(func() error {
|
||||
state, err := LoadMetricState(ctx, client, ids[i])
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.NotFound {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
metrics[i] = metricdata.Metrics{
|
||||
|
@ -66,6 +71,11 @@ func (p *producer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, erro
|
|||
return nil, err
|
||||
}
|
||||
|
||||
metrics = slices.Filter(metrics, func(v metricdata.Metrics) bool { return v.Name != "" })
|
||||
if len(metrics) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return []metricdata.ScopeMetrics{
|
||||
{
|
||||
Scope: p.scope,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue