kmetrics

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: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ShutdownTimeout is the timeout for shutting down the Otel exporter
	ShutdownTimeout = 5 * time.Second
)

Variables

View Source
var (
	KeyFieldName              = attribute.Key("field_name")
	KeyDeprecatingField       = attribute.Key("deprecating_field")
	KeySimplificationField    = attribute.Key("simplification_field")
	KeyK8sMetadataTransformer = attribute.Key("k8s_metadata_transformer")
	KeyHelmInflator           = attribute.Key("helm_inflator")
	KeyBaseSource             = attribute.Key("base_source")
	KeyPatchField             = attribute.Key("patch_field")
	KeyTopTierField           = attribute.Key("top_tier_field")
)

Attribute keys for kustomize metrics

View Source
var (
	// KustomizeFieldCount is the number of times a particular field is used
	KustomizeFieldCount metric.Int64Gauge

	// KustomizeDeprecatingFields is the usage of fields that may become deprecated
	KustomizeDeprecatingFields metric.Int64Gauge

	// KustomizeSimplification is the usage of simplification transformers
	KustomizeSimplification metric.Int64Gauge

	// KustomizeK8sMetadata is the usage of builtin transformers
	KustomizeK8sMetadata metric.Int64Gauge

	// KustomizeHelmMetrics is the usage of helm
	KustomizeHelmMetrics metric.Int64Gauge

	// KustomizeBaseCount is the number of remote and local bases
	KustomizeBaseCount metric.Int64Gauge

	// KustomizePatchCount is the number of patches
	KustomizePatchCount metric.Int64Gauge

	// KustomizeTopTierMetrics is the usage of high level metrics
	KustomizeTopTierMetrics metric.Int64Gauge

	// KustomizeResourceCount is the number of resources outputted by `kustomize build`
	KustomizeResourceCount metric.Int64Gauge

	// KustomizeExecutionTime is the execution time of `kustomize build`
	KustomizeExecutionTime metric.Float64Histogram
)

Functions

func InitializeOTelKustomizeMetrics

func InitializeOTelKustomizeMetrics() error

InitializeOTelKustomizeMetrics initializes OpenTelemetry Kustomize metrics instruments

func RecordKustomizeExecutionTime

func RecordKustomizeExecutionTime(ctx context.Context, executionTime float64)

RecordKustomizeExecutionTime produces measurement for KustomizeExecutionTime view

func RecordKustomizeFieldCountData

func RecordKustomizeFieldCountData(ctx context.Context, fieldCountData *KustomizeFieldMetrics)

RecordKustomizeFieldCountData records all data relevant to the kustomization's field counts

func RecordKustomizeResourceCount

func RecordKustomizeResourceCount(ctx context.Context, resourceCount int)

RecordKustomizeResourceCount produces measurement for KustomizeResourceCount view

func RegisterOTelExporter

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

RegisterOTelExporter creates the OTLP metrics exporter.

func RunKustomizeBuild

func RunKustomizeBuild(ctx context.Context, sendMetrics bool, inputDir string, flags ...string) (string, error)

RunKustomizeBuild runs `kustomize build` with the provided arguments. inputDir is the directory upon which to invoke `kustomize build`, and flags is what flags to run on it.

For example: RunKustomizeBuild(".", []string{"--enable-helm"}) will run `kustomize build . --enable-helm`.

The argument sendMetrics determines whether to send metrics about kustomize to Google Cloud.

Prior to running `kustomize build`, the wrapper will check the `buildMetadata` field of the kustomization file. By default, we would like to enable the `buildMetadata.originAnnotations`. If the kustomization file does not include it already, we add it and remove it afterwards.

Types

type KustomizeFieldMetrics

type KustomizeFieldMetrics struct {
	// fieldCount is how many times a given field is used in an instance
	// of kustomize build (including in bases and overlays)
	FieldCount map[string]int

	// TopTierCount looks at the fields Resources, Generators, SecretGenerator,
	// ConfigMapGenerator, Transformers, and Validators, and counts how many
	// of each are being used in a kustomization, e.g. for resources, how
	// many total resource paths there are.
	TopTierCount map[string]int

	// PatchCount looks at the patches, patchesStrategicMerge, and patchesJson6902
	// and counts how many patches are in each field
	PatchCount map[string]int

	// BaseCount counts the number of remote and local bases
	BaseCount map[string]int

	// HelmMetrics counts the usage of helm in kustomize, if the new helm generator
	// function is used and how many charts are being inflated with the builtin
	// helm fields
	HelmMetrics map[string]int

	// K8sMetadata looks at the usage of builtin transformers related to kubernetes
	// object metadata
	K8sMetadata map[string]int

	// SimplMetrics looks at the usage of simplification transformers images, replicas,
	// and replacements
	SimplMetrics map[string]int

	// DeprecationMetrics looks at the usage of fields that may become deprecated
	DeprecationMetrics map[string]int
}

KustomizeFieldMetrics stores kustomize metrics

Jump to

Keyboard shortcuts

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