Skip to content

Commit 59e0267

Browse files
L3n41ctbavelierlevan-m
authored
[CONTINT-4643] Add an option to configure KSM custom resource metrics collection (#1927)
Co-authored-by: Timothée Bavelier <[email protected]> Co-authored-by: levan-m <[email protected]>
1 parent 2a49036 commit 59e0267

25 files changed

+3411
-12
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ core,github.com/go-logr/zapr,Apache-2.0
5353
core,github.com/go-openapi/jsonpointer,Apache-2.0
5454
core,github.com/go-openapi/jsonreference,Apache-2.0
5555
core,github.com/go-openapi/swag,Apache-2.0
56+
core,github.com/gobuffalo/flect,MIT
5657
core,github.com/gobwas/glob,MIT
5758
core,github.com/gogo/protobuf,BSD-3-Clause
5859
core,github.com/golang/protobuf,BSD-3-Clause

api/datadoghq/v2alpha1/datadogagent_types.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,156 @@ type KubeStateMetricsCoreFeatureConfig struct {
823823
// This must point to a ConfigMap containing a valid cluster check configuration.
824824
// +optional
825825
Conf *CustomConfig `json:"conf,omitempty"`
826+
827+
// `CollectCrMetrics` defines custom resources for the kube-state-metrics core check to collect.
828+
//
829+
// The datadog agent uses the same logic as upstream `kube-state-metrics`. So is its configuration.
830+
// The exact structure and existing fields of each item in this list can be found in:
831+
// https://github.com/kubernetes/kube-state-metrics/blob/main/docs/metrics/extend/customresourcestate-metrics.md
832+
//
833+
// +optional
834+
// +listType=atomic
835+
CollectCrMetrics []Resource `json:"collectCrMetrics,omitempty"`
836+
}
837+
838+
// Resource configures a custom resource for metric generation.
839+
type Resource struct {
840+
// MetricNamePrefix defines a prefix for all metrics of the resource.
841+
// If set to "", no prefix will be added.
842+
// Example: If set to "foo", MetricNamePrefix will be "foo_<metric>".
843+
// +optional
844+
MetricNamePrefix *string `json:"metricNamePrefix,omitempty" yaml:"metricNamePrefix,omitempty"`
845+
846+
// GroupVersionKind of the custom resource to be monitored.
847+
GroupVersionKind GroupVersionKind `json:"groupVersionKind,omitempty" yaml:"groupVersionKind,omitempty"`
848+
849+
// Labels are added to all metrics. If the same key is used in a metric, the value from the metric will overwrite the value here.
850+
Labels `json:",inline" yaml:",inline"`
851+
852+
// Metrics are the custom resource fields to be collected.
853+
Metrics []Generator `json:"metrics,omitempty" yaml:"metrics,omitempty"`
854+
855+
// ResourcePlural sets the plural name of the resource. Defaults to the plural version of the Kind according to flect.Pluralize.
856+
// +optional
857+
ResourcePlural string `json:"resourcePlural,omitempty" yaml:"resourcePlural,omitempty"`
858+
}
859+
860+
// GroupVersionKind is the Kubernetes group, version, and kind of a resource.
861+
type GroupVersionKind struct {
862+
Group string `json:"group,omitempty" yaml:"group,omitempty"`
863+
Version string `json:"version,omitempty" yaml:"version,omitempty"`
864+
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
865+
}
866+
867+
// Labels is common configuration of labels to add to metrics.
868+
type Labels struct {
869+
// CommonLabels are added to all metrics.
870+
// +optional
871+
CommonLabels map[string]string `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
872+
// LabelsFromPath adds additional labels where the value is taken from a field in the resource.
873+
// +optional
874+
LabelsFromPath map[string][]string `json:"labelsFromPath,omitempty" yaml:"labelsFromPath,omitempty"`
875+
}
876+
877+
// Generator describes a unique metric name.
878+
type Generator struct {
879+
// Name of the metric. Subject to prefixing based on the configuration of the Resource.
880+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
881+
// Help text for the metric.
882+
// +optional
883+
Help string `json:"help,omitempty" yaml:"help,omitempty"`
884+
// Each targets a value or values from the resource.
885+
Each Metric `json:"each,omitempty" yaml:"each,omitempty"`
886+
887+
// Labels are added to all metrics. Labels from Each will overwrite these if using the same key.
888+
Labels `json:",inline" yaml:",inline"` // json will inline because it is already tagged
889+
}
890+
891+
// Metric defines a metric to expose.
892+
// +union
893+
type Metric struct {
894+
// Type defines the type of the metric.
895+
// +unionDiscriminator
896+
Type MetricType `json:"type,omitempty" yaml:"type,omitempty"`
897+
898+
// Gauge defines a gauge metric.
899+
// +optional
900+
Gauge *MetricGauge `json:"gauge,omitempty" yaml:"gauge,omitempty"`
901+
// StateSet defines a state set metric.
902+
// +optional
903+
StateSet *MetricStateSet `json:"stateSet,omitempty" yaml:"stateSet,omitempty"`
904+
// Info defines an info metric.
905+
// +optional
906+
Info *MetricInfo `json:"info,omitempty" yaml:"info,omitempty"`
907+
}
908+
909+
// Type represents the type of the metric. See https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#metric-types.
910+
type MetricType string
911+
912+
// Supported metric types.
913+
var (
914+
915+
// Gauge defines an OpenMetrics gauge.
916+
Gauge MetricType = "gauge"
917+
918+
// Info defines an OpenMetrics info.
919+
Info MetricType = "info"
920+
921+
// StateSet defines an OpenMetrics stateset.
922+
StateSet MetricType = "stateset"
923+
924+
// Counter defines an OpenMetrics counter.
925+
Counter MetricType = "counter"
926+
)
927+
928+
// MetricMeta are variables which may used for any metric type.
929+
type MetricMeta struct {
930+
// LabelsFromPath adds additional labels where the value of the label is taken from a field under Path.
931+
// +optional
932+
LabelsFromPath map[string][]string `json:"labelsFromPath,omitempty" yaml:"labelsFromPath,omitempty"`
933+
// Path is the path to to generate metric(s) for.
934+
Path []string `json:"path" yaml:"path"`
935+
}
936+
937+
// MetricGauge targets a Path that may be a single value, array, or object. Arrays and objects will generate a metric per element.
938+
// Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#gauge
939+
type MetricGauge struct {
940+
MetricMeta `json:",inline" yaml:",inline"`
941+
942+
// ValueFrom is the path to a numeric field under Path that will be the metric value.
943+
// +optional
944+
ValueFrom []string `json:"valueFrom,omitempty" yaml:"valueFrom,omitempty"`
945+
// LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key.
946+
// +optional
947+
LabelFromKey string `json:"labelFromKey,omitempty" yaml:"labelFromKey,omitempty"`
948+
// NilIsZero indicates that if a value is nil it will be treated as zero value.
949+
// +optional
950+
NilIsZero bool `json:"nilIsZero,omitempty" yaml:"nilIsZero,omitempty"`
951+
}
952+
953+
// MetricInfo is a metric which is used to expose textual information.
954+
// Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#info
955+
type MetricInfo struct {
956+
MetricMeta `json:",inline" yaml:",inline"`
957+
// LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key.
958+
// +optional
959+
LabelFromKey string `json:"labelFromKey,omitempty" yaml:"labelFromKey,omitempty"`
960+
}
961+
962+
// MetricStateSet is a metric which represent a series of related boolean values, also called a bitset.
963+
// Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#stateset
964+
type MetricStateSet struct {
965+
MetricMeta `json:",inline" yaml:",inline"`
966+
967+
// List is the list of values to expose a value for.
968+
// +optional
969+
List []string `json:"list,omitempty" yaml:"list,omitempty"`
970+
// LabelName is the key of the label which is used for each entry in List to expose the value.
971+
// +optional
972+
LabelName string `json:"labelName,omitempty" yaml:"labelName,omitempty"`
973+
// ValueFrom is the subpath to compare the list to.
974+
// +optional
975+
ValueFrom []string `json:"valueFrom,omitempty" yaml:"valueFrom,omitempty"`
826976
}
827977

828978
// OtelCollectorFeatureConfig contains the configuration for the otel-agent.

0 commit comments

Comments
 (0)