Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .chloggen/allocator-scrapeclasses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for prometheus scrape classes

# One or more tracking issues related to the change
issues: [3600]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
Added support for configuring `scrapeClasses` when using the PrometheusCR-feature of the target allocator.
The format of the `scrapeClasses` array is exactly as same as `spec.scrapeClasses` of the `Prometheus` CRD.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ spec:
enabled: true
serviceMonitorSelector: {}
podMonitorSelector: {}
scrapeClasses: []
config:
receivers:
prometheus:
Expand All @@ -724,6 +725,9 @@ spec:
EOF
```

The `scrapeClasses` attribute refers to the ScrapeClass feature of the Prometheus Operator.
Refer to https://prometheus-operator.dev/docs/developer/scrapeclass/ to learn more about scrape classes.

## Configure resource attributes

The OpenTelemetry Operator can automatically set resource attributes as defined in the
Expand Down
2 changes: 2 additions & 0 deletions apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde
PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{
Enabled: in.PrometheusCR.Enabled,
ScrapeInterval: in.PrometheusCR.ScrapeInterval,
ScrapeClasses: in.PrometheusCR.ScrapeClasses,
// prometheus_cr.pod_monitor_selector shouldn't be nil when selector is empty
PodMonitorSelector: &metav1.LabelSelector{
MatchLabels: in.PrometheusCR.PodMonitorSelector,
Expand Down Expand Up @@ -458,6 +459,7 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat
PrometheusCR: OpenTelemetryTargetAllocatorPrometheusCR{
Enabled: in.PrometheusCR.Enabled,
ScrapeInterval: in.PrometheusCR.ScrapeInterval,
ScrapeClasses: in.PrometheusCR.ScrapeClasses,
PodMonitorSelector: podMonitorSelector,
ServiceMonitorSelector: serviceMonitorSelector,
},
Expand Down
8 changes: 8 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
)

// ManagementStateType defines the type for CR management states.
Expand Down Expand Up @@ -389,6 +391,12 @@ type OpenTelemetryTargetAllocatorPrometheusCR struct {
// +kubebuilder:default:="30s"
// +kubebuilder:validation:Format:=duration
ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"`
// ScrapeClasses to be referenced by PodMonitors and ServiceMonitors to include common configuration.
// If specified, expects an array of ScrapeClass objects as specified by https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ScrapeClass.
// +optional
// +listType=atomic
// +kubebuilder:pruning:PreserveUnknownFields
ScrapeClasses []v1beta1.AnyConfig `json:"scrapeClasses,omitempty"`
// PodMonitors to be selected for target discovery.
// This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a
// PodMonitor's meta labels. The requirements are ANDed.
Expand Down
7 changes: 7 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions apis/v1beta1/targetallocator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type TargetAllocatorPrometheusCR struct {
// +kubebuilder:default:="30s"
// +kubebuilder:validation:Format:=duration
ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"`
// ScrapeClasses to be referenced by PodMonitors and ServiceMonitors to include common configuration.
// If specified, expects an array of ScrapeClass objects as specified by https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ScrapeClass.
// +optional
// +listType=atomic
// +kubebuilder:pruning:PreserveUnknownFields
ScrapeClasses []AnyConfig `json:"scrapeClasses,omitempty"`
// PodMonitors to be selected for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
Expand Down
7 changes: 7 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,12 @@ spec:
additionalProperties:
type: string
type: object
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeInterval:
default: 30s
format: duration
Expand Down Expand Up @@ -8027,6 +8033,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,12 @@ spec:
additionalProperties:
type: string
type: object
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeInterval:
default: 30s
format: duration
Expand Down Expand Up @@ -8026,6 +8032,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
3 changes: 2 additions & 1 deletion cmd/otel-allocator/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ type PrometheusCRConfig struct {
ScrapeConfigNamespaceSelector *metav1.LabelSelector `yaml:"scrape_config_namespace_selector,omitempty"`
ProbeSelector *metav1.LabelSelector `yaml:"probe_selector,omitempty"`
ProbeNamespaceSelector *metav1.LabelSelector `yaml:"probe_namespace_selector,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `yaml:"scrape_protocols,omitempty"`
ScrapeInterval model.Duration `yaml:"scrape_interval,omitempty"`
EvaluationInterval model.Duration `yaml:"evaluation_interval,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `yaml:"scrape_protocols,omitempty"`
ScrapeClasses []monitoringv1.ScrapeClass `yaml:"scrape_classes,omitempty"`
}

type HTTPSServerConfig struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/otel-allocator/internal/watcher/promOperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func NewPrometheusCRWatcher(
ProbeNamespaceSelector: cfg.PrometheusCR.ProbeNamespaceSelector,
ServiceDiscoveryRole: &serviceDiscoveryRole,
ScrapeProtocols: cfg.PrometheusCR.ScrapeProtocols,
ScrapeClasses: cfg.PrometheusCR.ScrapeClasses,
},
EvaluationInterval: monitoringv1.Duration(cfg.PrometheusCR.EvaluationInterval.String()),
},
Expand Down
64 changes: 64 additions & 0 deletions cmd/otel-allocator/internal/watcher/promOperator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestLoadConfig(t *testing.T) {
name string
serviceMonitors []*monitoringv1.ServiceMonitor
podMonitors []*monitoringv1.PodMonitor
scrapeClasses []*monitoringv1.ScrapeClass
scrapeConfigs []*promv1alpha1.ScrapeConfig
probes []*monitoringv1.Probe
want *promconfig.Config
Expand Down Expand Up @@ -919,6 +920,68 @@ func TestLoadConfig(t *testing.T) {
},
},
},
{
name: "pod monitor with referenced scrape class",
podMonitors: []*monitoringv1.PodMonitor{
{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: namespace,
},
Spec: monitoringv1.PodMonitorSpec{
JobLabel: "test",
ScrapeClassName: ptr.To("attach-node-metadata"),
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: &portName,
},
},
},
},
},
cfg: allocatorconfig.Config{
PrometheusCR: allocatorconfig.PrometheusCRConfig{
PodMonitorSelector: &metav1.LabelSelector{},
ScrapeClasses: []monitoringv1.ScrapeClass{
{
Name: "attach-node-metadata",
AttachMetadata: &monitoringv1.AttachMetadata{
Node: ptr.To(true),
},
},
},
},
},
want: &promconfig.Config{
ScrapeConfigs: []*promconfig.ScrapeConfig{
{
JobName: "podMonitor/test/simple/0",
ScrapeInterval: model.Duration(60 * time.Second),
ScrapeProtocols: promconfig.DefaultScrapeProtocols,
ScrapeTimeout: model.Duration(10 * time.Second),
HonorTimestamps: true,
HonorLabels: false,
Scheme: "http",
MetricsPath: "/metrics",
ServiceDiscoveryConfigs: []discovery.Config{
&kubeDiscovery.SDConfig{
Role: "pod",
NamespaceDiscovery: kubeDiscovery.NamespaceDiscovery{
Names: []string{namespace},
IncludeOwnNamespace: false,
},
HTTPClientConfig: config.DefaultHTTPClientConfig,
AttachMetadata: kubeDiscovery.AttachMetadataConfig{
Node: true, // Added by scrape-class!
},
},
},
HTTPClientConfig: config.DefaultHTTPClientConfig,
EnableCompression: true,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1346,6 +1409,7 @@ func getTestPrometheusCRWatcher(
ProbeNamespaceSelector: cfg.PrometheusCR.ProbeNamespaceSelector,
ScrapeConfigSelector: cfg.PrometheusCR.ScrapeConfigSelector,
ScrapeConfigNamespaceSelector: cfg.PrometheusCR.ScrapeConfigNamespaceSelector,
ScrapeClasses: cfg.PrometheusCR.ScrapeClasses,
ServiceDiscoveryRole: &serviceDiscoveryRole,
},
EvaluationInterval: monitoringv1.Duration(cfg.PrometheusCR.EvaluationInterval.String()),
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,12 @@ spec:
additionalProperties:
type: string
type: object
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeInterval:
default: 30s
format: duration
Expand Down Expand Up @@ -8013,6 +8019,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/opentelemetry.io_targetallocators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,12 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeClasses:
items:
type: object
type: array
x-kubernetes-list-type: atomic
x-kubernetes-preserve-unknown-fields: true
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down
16 changes: 16 additions & 0 deletions docs/api/opentelemetrycollectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -13477,6 +13477,14 @@ PodMonitor's meta labels. The requirements are ANDed.
Empty or nil map matches all pod monitors.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scrapeClasses</b></td>
<td>[]object</td>
<td>
ScrapeClasses to be referenced by PodMonitors and ServiceMonitors to include common configuration.
If specified, expects an array of ScrapeClass objects as specified by https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ScrapeClass.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scrapeInterval</b></td>
<td>string</td>
Expand Down Expand Up @@ -33557,6 +33565,14 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null
label selector matches no objects.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scrapeClasses</b></td>
<td>[]object</td>
<td>
ScrapeClasses to be referenced by PodMonitors and ServiceMonitors to include common configuration.
If specified, expects an array of ScrapeClass objects as specified by https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ScrapeClass.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspectargetallocatorprometheuscrscrapeconfigselector">scrapeConfigSelector</a></b></td>
<td>object</td>
Expand Down
8 changes: 8 additions & 0 deletions docs/api/targetallocators.md
Original file line number Diff line number Diff line change
Expand Up @@ -9591,6 +9591,14 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null
label selector matches no objects.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>scrapeClasses</b></td>
<td>[]object</td>
<td>
ScrapeClasses to be referenced by PodMonitors and ServiceMonitors to include common configuration.
If specified, expects an array of ScrapeClass objects as specified by https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ScrapeClass.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#targetallocatorspecprometheuscrscrapeconfigselector">scrapeConfigSelector</a></b></td>
<td>object</td>
Expand Down
4 changes: 4 additions & 0 deletions internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func ConfigMap(params Params) (*corev1.ConfigMap, error) {
prometheusCRConfig["scrape_interval"] = taSpec.PrometheusCR.ScrapeInterval.Duration
}

if taSpec.PrometheusCR.ScrapeClasses != nil {
prometheusCRConfig["scrape_classes"] = taSpec.PrometheusCR.ScrapeClasses
}

if taSpec.PrometheusCR.AllowNamespaces != nil {
prometheusCRConfig["allow_namespaces"] = taSpec.PrometheusCR.AllowNamespaces
}
Expand Down
Loading
Loading