metrics

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APICallDurationName is the name of API duration metric
	APICallDurationName = "api_duration_seconds"
	// ReconcilerErrorsName is the name of reconciler error count metric
	ReconcilerErrorsName = "reconciler_errors"
	// PipelineErrorName is the name of pipeline error status metric.
	PipelineErrorName = "pipeline_error_observed"
	// ReconcileDurationName is the name of reconcile duration metric
	ReconcileDurationName = "reconcile_duration_seconds"
	// ParserDurationName is the name of parser duration metric
	ParserDurationName = "parser_duration_seconds"
	// LastSyncName is the name of last sync timestamp metric
	LastSyncName = "last_sync_timestamp"
	// DeclaredResourcesName is the name of declared resource count metric
	DeclaredResourcesName = "declared_resources"
	// ApplyOperationsName is the name of apply operations count metric
	ApplyOperationsName = "apply_operations_total"
	// ApplyDurationName is the name of apply duration metric
	ApplyDurationName = "apply_duration_seconds"
	// ResourceFightsName is the name of resource fight count metric
	ResourceFightsName = "resource_fights_total"
	// RemediateDurationName is the name of remediate duration metric
	RemediateDurationName = "remediate_duration_seconds"
	// LastApplyName is the name of last apply timestamp metric
	LastApplyName = "last_apply_timestamp"
	// ResourceConflictsName is the name of resource conflict count metric
	ResourceConflictsName = "resource_conflicts_total"
	// InternalErrorsName is the name of internal error count metric
	InternalErrorsName = "internal_errors_total"
)
View Source
const (
	// OpenTelemetry is the app label for all otel resources.
	OpenTelemetry = "opentelemetry"

	// OtelAgentName is the name of the OpenTelemetry Agent.
	OtelAgentName = "otel-agent"

	// OtelCollectorName is the name of the OpenTelemetry Collector.
	OtelCollectorName = "otel-collector"

	// OtelCollectorGooglecloud is the name of the OpenTelemetry Collector ConfigMap that contains Googlecloud exporter.
	OtelCollectorGooglecloud = "otel-collector-googlecloud"

	// OtelCollectorCustomCM is the name of the custom OpenTelemetry Collector ConfigMap.
	OtelCollectorCustomCM = "otel-collector-custom"
)
View Source
const (
	// StatusSuccess is the string value for the status key indicating success
	StatusSuccess = "success"
	// StatusError is the string value for the status key indicating failure/errors
	StatusError = "error"
	// CommitNone is the string value for the commit key indicating that no
	// commit has been synced.
	CommitNone = "NONE"
	// ApplierController is the string value for the applier controller in the multi-repo mode
	ApplierController = "applier"
	// RemediatorController is the string value for the remediator controller in the multi-repo mode
	RemediatorController = "remediator"
)
View Source
const (
	// ShutdownTimeout is the timeout for shutting down the Otel exporter
	ShutdownTimeout = 5 * time.Second
)

Variables

View Source
var (
	// APICallDuration metric measures the latency of API server calls.
	APICallDuration metric.Float64Histogram

	// ReconcilerErrors metric measures the number of errors in the reconciler.
	ReconcilerErrors metric.Int64Gauge

	// PipelineError metric measures the error by components when syncing a commit.
	// Definition here must exactly match the definition in the resource-group
	// controller, or the Prometheus exporter will error. b/247516388
	// https://github.com/GoogleContainerTools/kpt-resource-group/blob/main/controllers/metrics/metrics.go#L88
	PipelineError metric.Int64Gauge

	// ReconcileDuration metric measures the latency of reconcile events.
	ReconcileDuration metric.Float64Histogram

	// ParserDuration metric measures the latency of the parse-apply-watch loop.
	ParserDuration metric.Float64Histogram

	// LastSync metric measures the timestamp of the latest Git sync.
	LastSync metric.Int64Gauge

	// DeclaredResources metric measures the number of declared resources parsed from Git.
	DeclaredResources metric.Int64Gauge

	// ApplyOperations metric measures the number of applier apply events.
	ApplyOperations metric.Int64Counter

	// ApplyDuration metric measures the latency of applier apply events.
	ApplyDuration metric.Float64Histogram

	// ResourceFights metric measures the number of resource fights.
	ResourceFights metric.Int64Counter

	// RemediateDuration metric measures the latency of remediator reconciliation events.
	RemediateDuration metric.Float64Histogram

	// LastApply metric measures the timestamp of the most recent applier apply event.
	LastApply metric.Int64Gauge

	// ResourceConflicts metric measures the number of resource conflicts.
	ResourceConflicts metric.Int64Counter

	// InternalErrors metric measures the number of unexpected internal errors triggered by defensive checks in Config Sync.
	InternalErrors metric.Int64Counter
)
View Source
var (
	// KeyName groups metrics by the reconciler name. Possible values: root-reconciler, ns-reconciler-<namespace>
	// TODO b/208316928 remove this key from pipeline_error_observed metric once same metric in Resource Group Controller has this tag removed
	KeyName = attribute.Key("name")

	// KeyReconcilerType groups metrics by the reconciler type. Possible values: root, namespace.
	// TODO: replace with configsync.sync.kind resource attribute
	KeyReconcilerType = attribute.Key("reconciler")

	// KeyOperation groups metrics by their operation. Possible values: create, patch, update, delete.
	KeyOperation = attribute.Key("operation")

	// KeyController groups metrics by their controller. Possible values: applier, remediator.
	KeyController = attribute.Key("controller")

	// KeyComponent groups metrics by their component. Possible values: source, sync, rendering, readiness(from Resource Group Controller).
	KeyComponent = attribute.Key("component")

	// KeyExportedComponent groups metrics by their component.
	// The "component" metric tag overlaps with a resource tag exported by
	// resource_to_telemetry_conversion when using Prometheus. So it's renamed
	// "exported_component" when exported to Prometheus.
	// TODO: Fix this naming overlap by renaming the "component" metric tag.
	// Possible values: source, sync, rendering, readiness (from Resource Group Controller).
	KeyExportedComponent = attribute.Key("exported_component")

	// KeyErrorClass groups metrics by their error code.
	KeyErrorClass = attribute.Key("errorclass")

	// KeyStatus groups metrics by their status. Possible values: success, error.
	KeyStatus = attribute.Key("status")

	// KeyInternalErrorSource groups the InternalError metrics by their source. Possible values: parser, differ, remediator.
	KeyInternalErrorSource = attribute.Key("source")

	// KeyParserSource groups the metrics for the parser by their source. Possible values: read, parse, update.
	KeyParserSource = attribute.Key("source")

	// KeyTrigger groups metrics by their trigger. Possible values: retry, watchUpdate, managementConflict, resync, reimport.
	KeyTrigger = attribute.Key("trigger")

	// KeyCommit groups metrics by their git commit. Even though this tag has a high cardinality,
	// it is only used by the `last_sync_timestamp` and `last_apply_timestamp` metrics.
	// These are both aggregated as LastValue metrics so the number of recorded values will always be
	// at most 1 per git commit.
	KeyCommit = attribute.Key("commit")

	// KeyContainer groups metrics by their container names. Possible values: reconciler, git-sync.
	// TODO: replace with k8s.container.name resource attribute
	KeyContainer = attribute.Key("container")

	// KeyResourceType groups metrics by their resource types. Possible values: cpu, memory.
	KeyResourceType = attribute.Key("resource")
)
View Source
var (
	// ResourceKeySyncKind groups metrics by the Sync kind. Possible values: RootSync, RepoSync.
	ResourceKeySyncKind = attribute.Key("configsync_sync_kind")

	// ResourceKeySyncName groups metrics by the Sync name.
	ResourceKeySyncName = attribute.Key("configsync_sync_name")

	// ResourceKeySyncNamespace groups metrics by the Sync namespace.
	ResourceKeySyncNamespace = attribute.Key("configsync_sync_namespace")

	// ResourceKeySyncGeneration groups metrics by the Sync metadata.generation.
	ResourceKeySyncGeneration = attribute.Key("configsync_sync_generation")

	// ResourceKeyDeploymentName groups metrics by k8s deployment name.
	ResourceKeyDeploymentName = attribute.Key("k8s_deployment_name")

	// ResourceKeyPodName groups metrics by k8s pod name.
	ResourceKeyPodName = attribute.Key("k8s_pod_name")
)

The following metric tag keys are available from the otel-collector Prometheus exporter. They are created from resource attributes using the resource_to_telemetry_conversion feature.

Functions

func CollectorConfigOTLPGooglecloudYAML

func CollectorConfigOTLPGooglecloudYAML() (string, error)

CollectorConfigOTLPGooglecloudYAML returns the otel-collector-googlecloud config as YAML using OTLP.

func InitializeOTelMetrics

func InitializeOTelMetrics() error

InitializeOTelMetrics initializes OpenTelemetry metrics instruments

func RecordAPICallDuration

func RecordAPICallDuration(ctx context.Context, operation, status string, startTime time.Time)

RecordAPICallDuration produces a measurement for the APICallDuration view.

func RecordApplyDuration

func RecordApplyDuration(ctx context.Context, status, commit string, startTime time.Time)

RecordApplyDuration produces measurements for the ApplyDuration and LastApplyTimestamp views.

func RecordApplyOperation

func RecordApplyOperation(ctx context.Context, controller, operation, status string)

RecordApplyOperation produces a measurement for the ApplyOperations view.

func RecordDeclaredResources

func RecordDeclaredResources(ctx context.Context, commit string, numResources int)

RecordDeclaredResources produces a measurement for the DeclaredResources view.

func RecordInternalError

func RecordInternalError(ctx context.Context, source string)

RecordInternalError produces measurements for the InternalErrors view.

func RecordLastSync

func RecordLastSync(ctx context.Context, status, commit string, timestamp time.Time)

RecordLastSync produces a measurement for the LastSync view.

func RecordParserDuration

func RecordParserDuration(ctx context.Context, trigger, source, status string, startTime time.Time)

RecordParserDuration produces a measurement for the ParserDuration view.

func RecordPipelineError

func RecordPipelineError(ctx context.Context, reconcilerType, component string, errLen int)

RecordPipelineError produces a measurement for the PipelineError view

func RecordReconcileDuration

func RecordReconcileDuration(ctx context.Context, status string, startTime time.Time)

RecordReconcileDuration produces a measurement for the ReconcileDuration view.

func RecordReconcilerErrors

func RecordReconcilerErrors(ctx context.Context, component string, errs []v1beta1.ConfigSyncError)

RecordReconcilerErrors produces a measurement for the ReconcilerErrors view.

func RecordRemediateDuration

func RecordRemediateDuration(ctx context.Context, status string, startTime time.Time)

RecordRemediateDuration produces measurements for the RemediateDuration view.

func RecordResourceConflict

func RecordResourceConflict(ctx context.Context, commit string)

RecordResourceConflict produces measurements for the ResourceConflicts view.

func RecordResourceFight

func RecordResourceFight(ctx context.Context, _ string)

RecordResourceFight produces measurements for the ResourceFights view.

func RegisterOTelExporter

func RegisterOTelExporter(ctx context.Context, containerName string) (*otlpmetricgrpc.Exporter, error)

RegisterOTelExporter creates the OTLP metrics exporter.

func StatusTagKey

func StatusTagKey(err error) string

StatusTagKey returns a string representation of the error, if it exists, otherwise success.

func StatusTagValueFromSummary

func StatusTagValueFromSummary(summary *v1beta1.ErrorSummary) string

StatusTagValueFromSummary returns error if the summary indicates at least 1 error, otherwise success.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL