Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ServiceMonitors to gather metrics from the OTEL Operands #1874

Merged
merged 38 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
621888a
Allow the creation of ServiceMonitors to gather metrics from the Open…
iblancasa Jun 27, 2023
e5fb93f
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jun 28, 2023
66d5660
Add missing changelog
iblancasa Jun 28, 2023
ab26178
Fix unprotected statement
iblancasa Jun 28, 2023
796b323
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jun 28, 2023
80e25f5
Fix lint issues
iblancasa Jun 28, 2023
7880104
Merge branch 'main' into feature/1768
iblancasa Jun 28, 2023
638853f
Merge branch 'feature/1768' of github.com:iblancasa/opentelemetry-ope…
iblancasa Jun 28, 2023
4d5e3d7
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jun 28, 2023
3c2bc7d
Merge branch 'main' into feature/1768
iblancasa Jun 30, 2023
42c6c90
Merge branch 'feature/1768' of github.com:iblancasa/opentelemetry-ope…
iblancasa Jul 10, 2023
27e2a7e
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 10, 2023
4e718df
Apply changes requested in code review
iblancasa Jul 10, 2023
90b070b
Add missing generated files
iblancasa Jul 11, 2023
a5953e7
Change the way to enable the feature flag
iblancasa Jul 11, 2023
5604f1f
Change the way to enable the feature flag
iblancasa Jul 11, 2023
3101866
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 11, 2023
8fe848c
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 12, 2023
7a66076
Fix merge
iblancasa Jul 12, 2023
17e4bb5
Fix enable feature flag
iblancasa Jul 12, 2023
4f79a2d
Merge branch 'main' into feature/1768
iblancasa Jul 13, 2023
b50e2ac
Merge branch 'feature/1768' of github.com:iblancasa/opentelemetry-ope…
iblancasa Jul 13, 2023
4653d83
Merge branch 'main' into feature/1768
iblancasa Jul 14, 2023
7bf6584
Merge branch 'main' into feature/1768
iblancasa Jul 14, 2023
9aade8b
Merge branch 'feature/1768' of github.com:iblancasa/opentelemetry-ope…
iblancasa Jul 17, 2023
f9fca96
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 17, 2023
f8af040
Change the name of the option and move the E2E tests to their own folder
iblancasa Jul 17, 2023
3791100
Fix unit test
iblancasa Jul 17, 2023
bd81e57
Fix docs
iblancasa Jul 17, 2023
cb1f6ba
Fix CRD field
iblancasa Jul 17, 2023
a259991
Fix CRD field
iblancasa Jul 17, 2023
25effa4
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 19, 2023
175c0dc
Add from version to feature gate
iblancasa Jul 19, 2023
61ee15a
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 21, 2023
1ca9357
Merge branch 'main' into feature/1768
iblancasa Jul 24, 2023
1dc416a
Merge branch 'feature/1768' of github.com:iblancasa/opentelemetry-ope…
iblancasa Jul 24, 2023
297af31
Move the E2E tests to their own section for the CI
iblancasa Jul 24, 2023
83d31d5
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa Jul 25, 2023
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
16 changes: 16 additions & 0 deletions .chloggen/1768-gather-metrics-from-collectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add the ability to the operator to create Service Monitors for the OpenTelemetry Collectors in order to gather the metrics they are generating

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

# (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:
27 changes: 27 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ type OpenTelemetryCollectorSpec struct {
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
// +optional
InitContainers []v1.Container `json:"initContainers,omitempty"`

// ObservabilitySpec defines how telemetry data gets handled.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability"
Observability ObservabilitySpec `json:"observability,omitempty"`
}

// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
Expand Down Expand Up @@ -345,6 +352,26 @@ type AutoscalerSpec struct {
TargetMemoryUtilization *int32 `json:"targetMemoryUtilization,omitempty"`
}

// MetricsConfigSpec defines a metrics config.
type MetricsConfigSpec struct {
// CreateServiceMonitors specifies if ServiceMonitors should be created for the OpenTelemetry Collector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document here, how this feature is enabled

//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create ServiceMonitors for OpenTelemetry Collector"
CreateServiceMonitors bool `json:"createServiceMonitors,omitempty"`
iblancasa marked this conversation as resolved.
Show resolved Hide resolved
}

// ObservabilitySpec defines how telemetry data gets handled.
type ObservabilitySpec struct {
// Metrics defines the metrics configuration for operands.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Metrics Config"
Metrics MetricsConfigSpec `json:"metrics,omitempty"`
}

// Probe defines the OpenTelemetry's pod probe config. Only Liveness probe is supported currently.
type Probe struct {
// Number of seconds after the container has started before liveness probes are initiated.
Expand Down
32 changes: 32 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.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ spec:
- kind: StatefulSets
name: ""
version: apps/v1
specDescriptors:
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: observability
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: observability.metrics
- description: CreateServiceMonitors specifies if ServiceMonitors should be
created for the OpenTelemetry Collector.
displayName: Create ServiceMonitors for OpenTelemetry Collector
path: observability.metrics.createServiceMonitors
version: v1alpha1
description: |-
OpenTelemetry is a collection of tools, APIs, and SDKs. You use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.
Expand Down Expand Up @@ -209,6 +220,18 @@ spec:
- get
- list
- update
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- networking.k8s.io
resources:
Expand Down
12 changes: 12 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,18 @@ spec:
This is only relevant to daemonset, statefulset, and deployment
mode
type: object
observability:
description: ObservabilitySpec defines how telemetry data gets handled.
properties:
metrics:
description: Metrics defines the metrics configuration for operands.
properties:
createServiceMonitors:
description: CreateServiceMonitors specifies if ServiceMonitors
should be created for the OpenTelemetry Collector.
type: boolean
type: object
type: object
podAnnotations:
additionalProperties:
type: 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 @@ -2946,6 +2946,18 @@ spec:
This is only relevant to daemonset, statefulset, and deployment
mode
type: object
observability:
description: ObservabilitySpec defines how telemetry data gets handled.
properties:
metrics:
description: Metrics defines the metrics configuration for operands.
properties:
createServiceMonitors:
description: CreateServiceMonitors specifies if ServiceMonitors
should be created for the OpenTelemetry Collector.
type: boolean
type: object
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ spec:
- kind: StatefulSets
name: ""
version: apps/v1
specDescriptors:
- description: ObservabilitySpec defines how telemetry data gets handled.
displayName: Observability
path: observability
- description: Metrics defines the metrics configuration for operands.
displayName: Metrics Config
path: observability.metrics
- description: CreateServiceMonitors specifies if ServiceMonitors should be
created for the OpenTelemetry Collector.
displayName: Create ServiceMonitors for OpenTelemetry Collector
path: observability.metrics.createServiceMonitors
version: v1alpha1
description: |-
OpenTelemetry is a collection of tools, APIs, and SDKs. You use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ rules:
- get
- list
- update
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- networking.k8s.io
resources:
Expand Down
11 changes: 11 additions & 0 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sync"

"github.com/go-logr/logr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/pkg/autodetect"
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/reconcile"
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
)

// OpenTelemetryCollectorReconciler reconciles a OpenTelemetryCollector object.
Expand Down Expand Up @@ -164,6 +166,11 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
"ingresses",
true,
},
{
reconcile.ServiceMonitors,
"service monitors",
true,
},
iblancasa marked this conversation as resolved.
Show resolved Hide resolved
{
reconcile.Self,
"opentelemetry",
Expand Down Expand Up @@ -251,6 +258,10 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er
Owns(&appsv1.DaemonSet{}).
Owns(&appsv1.StatefulSet{})

if featuregate.PrometheusOperatorIsAvailable.IsEnabled() {
builder.Owns(&monitoringv1.ServiceMonitor{})
}

autoscalingVersion := r.config.AutoscalingVersion()
if autoscalingVersion == autodetect.AutoscalingVersionV2 {
builder = builder.Owns(&autoscalingv2.HorizontalPodAutoscaler{})
Expand Down
61 changes: 61 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3736,6 +3736,13 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
NodeSelector to schedule OpenTelemetry Collector pods. This is only relevant to daemonset, statefulset, and deployment mode<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecobservability">observability</a></b></td>
<td>object</td>
<td>
ObservabilitySpec defines how telemetry data gets handled.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>podAnnotations</b></td>
<td>map[string]string</td>
Expand Down Expand Up @@ -8978,6 +8985,60 @@ Liveness config for the OpenTelemetry Collector except the probe handler which i
</table>


### OpenTelemetryCollector.spec.observability
<sup><sup>[↩ Parent](#opentelemetrycollectorspec)</sup></sup>



ObservabilitySpec defines how telemetry data gets handled.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#opentelemetrycollectorspecobservabilitymetrics">metrics</a></b></td>
<td>object</td>
<td>
Metrics defines the metrics configuration for operands.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.observability.metrics
<sup><sup>[↩ Parent](#opentelemetrycollectorspecobservability)</sup></sup>



Metrics defines the metrics configuration for operands.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>createServiceMonitors</b></td>
<td>boolean</td>
<td>
CreateServiceMonitors specifies if ServiceMonitors should be created for the OpenTelemetry Collector.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.podSecurityContext
<sup><sup>[↩ Parent](#opentelemetrycollectorspec)</sup></sup>

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/go-logr/logr v1.2.4
github.com/mitchellh/mapstructure v1.5.0
github.com/openshift/api v3.9.0+incompatible
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0
github.com/prometheus/prometheus v0.44.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -134,7 +135,7 @@ require (
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
Expand All @@ -146,9 +147,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230308161112-d77c459e9343 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading