Skip to content

Commit

Permalink
Add flags to enable/disable operand metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Jul 10, 2021
1 parent 3330035 commit f96b438
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func NewStartCommand() *cobra.Command {
cmd.Flags().Int32("cr-metrics-port", 8686, "The metrics port for Operator and/or Custom Resource based metrics")
cmd.Flags().String("jaeger-agent-hostport", "localhost:6831", "The location for the Jaeger Agent")
cmd.Flags().Bool("tracing-enabled", false, "Whether the Operator should report its own spans to a Jaeger instance")
cmd.Flags().Bool("operand-metrics-enabled", false, "Whether the Operator should report metrics about the operands.")

return cmd
}
Expand Down
57 changes: 31 additions & 26 deletions pkg/metrics/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package metrics
import (
"context"

"github.com/spf13/viper"

prometheusclient "github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -25,33 +27,36 @@ const meterName = "jaegertracing.io/jaeger"

// Bootstrap configures the OpenTelemetry meter provides with the prometheus exporter
func Bootstrap(ctx context.Context, namespace string, client client.Client) error {
tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer)
ctx, span := tracer.Start(ctx, "bootstrap")
defer span.End()
tracing.SetInstanceID(ctx, namespace)

config := prometheus.Config{
Registry: metrics.Registry.(*prometheusclient.Registry),
}
c := controller.New(
processor.New(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
if viper.GetBool("operand-metrics-enabled") {
tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer)
ctx, span := tracer.Start(ctx, "bootstrap")
defer span.End()
tracing.SetInstanceID(ctx, namespace)

config := prometheus.Config{
Registry: metrics.Registry.(*prometheusclient.Registry),
}
c := controller.New(
processor.New(
selector.NewWithHistogramDistribution(
histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
),
export.CumulativeExportKindSelector(),
processor.WithMemory(true),
),
export.CumulativeExportKindSelector(),
processor.WithMemory(true),
),
controller.WithResource(resource.NewWithAttributes([]attribute.KeyValue{}...)),
)
exporter, err := prometheus.NewExporter(config, c)
if err != nil {
controller.WithResource(resource.NewWithAttributes([]attribute.KeyValue{}...)),
)
exporter, err := prometheus.NewExporter(config, c)
if err != nil {
return tracing.HandleError(err, span)
}

global.SetMeterProvider(exporter.MeterProvider())

// Create metrics
instancesObservedValue := newInstancesMetric(client)
err = instancesObservedValue.Setup(ctx)
return tracing.HandleError(err, span)
}

global.SetMeterProvider(exporter.MeterProvider())

// Create metrics
instancesObservedValue := newInstancesMetric(client)
err = instancesObservedValue.Setup(ctx)
return tracing.HandleError(err, span)
return nil
}

0 comments on commit f96b438

Please sign in to comment.