Documentation
¶
Index ¶
- Constants
- type Config
- type Metrics
- func (m *Metrics) AddQueueDepth(ctx context.Context, delta int64)
- func (m *Metrics) AddReconcileInFlight(delta int64)
- func (m *Metrics) IncConnectFailure(ctx context.Context)
- func (m *Metrics) IncCreateFailure(ctx context.Context)
- func (m *Metrics) IncDeleteFailure(ctx context.Context)
- func (m *Metrics) IncFinalizerAddFailure(ctx context.Context)
- func (m *Metrics) IncFinalizerRemoveFailure(ctx context.Context)
- func (m *Metrics) IncGetFailure(ctx context.Context)
- func (m *Metrics) IncObserveFailure(ctx context.Context)
- func (m *Metrics) IncRateLimitDeferral(ctx context.Context, key string, reason ratelimit.DeferReason)
- func (m *Metrics) IncRateLimitHoldClamped(ctx context.Context, key string)
- func (m *Metrics) IncRateLimitSignal(ctx context.Context, key string, kind ratelimit.SignalKind)
- func (m *Metrics) IncReconcileErrorRequeue(ctx context.Context)
- func (m *Metrics) IncReconcileFailure(ctx context.Context)
- func (m *Metrics) IncReconcileRequeueAfter(ctx context.Context)
- func (m *Metrics) IncReconcileRequeueImmediate(ctx context.Context)
- func (m *Metrics) IncReconcileSuccess(ctx context.Context)
- func (m *Metrics) IncStartupFailure(ctx context.Context)
- func (m *Metrics) IncStartupSuccess(ctx context.Context)
- func (m *Metrics) IncStatusUpdateFailure(ctx context.Context)
- func (m *Metrics) IncUpdateFailure(ctx context.Context)
- func (m *Metrics) ObserveRateLimit(snapshot func() ratelimit.Snapshot)
- func (m *Metrics) RecordConnectDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordCreateDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordDeleteDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordFinalizerAddDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordFinalizerRemoveDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordGetDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordObserveDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordQueueOldestItemAge(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordQueueWaitDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordQueueWorkDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordReconcileDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordStatusUpdateDuration(ctx context.Context, d time.Duration)
- func (m *Metrics) RecordUpdateDuration(ctx context.Context, d time.Duration)
Constants ¶
const ( EnvEnabled = "OTEL_ENABLED" EnvTracingEnabled = "OTEL_TRACING_ENABLED" EnvExportInterval = "OTEL_EXPORT_INTERVAL" EnvDeploymentName = "DEPLOYMENT_NAME" EnvServiceVersion = "SERVICE_VERSION" )
The environment ConfigFromEnv reads: Krateo's OTel convention.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Enabled turns on OTLP metrics export.
Enabled bool
// TracingEnabled turns on OTLP trace export (docs/design-tracing.md §3.1).
// It is independent of Enabled.
TracingEnabled bool
// ServiceName sets the exported service.name, unless OTEL_SERVICE_NAME or
// OTEL_RESOURCE_ATTRIBUTES already name one. Empty leaves it to those, or
// to the SDK's default. There is no library-wide default: every provider
// would then export the same service.name.
ServiceName string
// ServiceVersion sets service.version, unless OTEL_RESOURCE_ATTRIBUTES
// names one. Main sets it from its build stamp, falling back to
// SERVICE_VERSION.
ServiceVersion string
// DeploymentName sets k8s.deployment.name and service.instance.id, each
// unless OTEL_RESOURCE_ATTRIBUTES names it. The chart passes the
// Deployment's own name as DEPLOYMENT_NAME.
DeploymentName string
// ExportInterval is the metrics export interval; 0 means 30s.
ExportInterval time.Duration
}
Config controls OpenTelemetry metrics and trace export.
func ConfigFromEnv ¶ added in v1.14.0
ConfigFromEnv reads Krateo's OTel convention into a Config:
- OTEL_ENABLED: metrics, default false.
- OTEL_TRACING_ENABLED: traces, default false, whatever OTEL_ENABLED says.
- OTEL_EXPORT_INTERVAL: the metrics export interval, as a Go duration.
- DEPLOYMENT_NAME: k8s.deployment.name and service.instance.id.
- SERVICE_VERSION: service.version.
An unparsable boolean or duration is an error. ServiceName is left for the caller to set. The library reads no environment by itself; main calls this.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics exposes a small set of low-cardinality counters and histograms for provider-runtime consumers.
func Setup ¶
func Setup(ctx context.Context, log logging.Logger, cfg Config) (*Metrics, func(context.Context) error, error)
Setup creates and configures the OTLP metrics and trace pipelines.
- It always sets the global propagator to W3C TraceContext and Baggage, before it checks either gate, so a provider's own otelhttp honours an inbound context even with export off.
- Enabled gates metrics. When it's false, Setup returns a nil *Metrics.
- TracingEnabled gates traces. When it's true, Setup builds an otlptracehttp exporter from the standard OTEL_* environment, with a batcher, and installs the TracerProvider as the OTel global and as tracing.SetTracerProvider. It passes no sampler and no span limits, so the SDK's OTEL_TRACES_SAMPLER and OTEL_SPAN_* handling apply.
- With tracing on, the traces protocol must be http/protobuf, following OTel's precedence: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL when it is set, otherwise OTEL_EXPORTER_OTLP_PROTOCOL; unset is fine.
- Metrics and traces share one resource.
The returned function shuts down the TracerProvider, which flushes its batcher, then the MeterProvider, and joins their errors. It is never nil.
func (*Metrics) AddReconcileInFlight ¶
func (*Metrics) IncConnectFailure ¶
func (*Metrics) IncCreateFailure ¶
func (*Metrics) IncDeleteFailure ¶
func (*Metrics) IncFinalizerAddFailure ¶
func (*Metrics) IncFinalizerRemoveFailure ¶
func (*Metrics) IncGetFailure ¶
func (*Metrics) IncObserveFailure ¶
func (*Metrics) IncRateLimitDeferral ¶ added in v1.9.0
func (m *Metrics) IncRateLimitDeferral(ctx context.Context, key string, reason ratelimit.DeferReason)
IncRateLimitDeferral counts one deferred external call for key.
func (*Metrics) IncRateLimitHoldClamped ¶ added in v1.12.0
IncRateLimitHoldClamped counts one throttled signal for key whose deadline was cut to the governor's MaxHold.
func (*Metrics) IncRateLimitSignal ¶ added in v1.9.0
IncRateLimitSignal counts one throttled or advisory signal for key.
func (*Metrics) IncReconcileErrorRequeue ¶
func (*Metrics) IncReconcileFailure ¶
func (*Metrics) IncReconcileRequeueAfter ¶
func (*Metrics) IncReconcileRequeueImmediate ¶
func (*Metrics) IncReconcileSuccess ¶
func (*Metrics) IncStartupFailure ¶
func (*Metrics) IncStartupSuccess ¶
func (*Metrics) IncStatusUpdateFailure ¶
func (*Metrics) IncUpdateFailure ¶
func (*Metrics) ObserveRateLimit ¶ added in v1.9.0
ObserveRateLimit makes snapshot the source of the rate-limit gauges. ratelimit.New calls it when its Options.Metrics is set.