-
Notifications
You must be signed in to change notification settings - Fork 450
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
Mixing Prometheus Exporter with Collector's ServiceMonitor leads to double-scraping of metrics #2251
Comments
Actually,your excepted result is not very good when there are other recevicer or exporter ports to add. we do not need care where the prometheus port to add to which services , but we need to get a way to make servicemonitor to match only one prometheus service . In my case ,i just overwrite the label "app.kubernetes.io/instance" of service "XXX-headless" with suffix "--headless", and it is worked well on my prometheus . To make this change work all the time, you need change the operator code of "internal/manifests/collector/service.go" like this const (
headlessLabel = "operator.opentelemetry.io/collector-headless-service"
headlessExists = "Exists"
// add the var
renameInstance = "app.kubernetes.io/instance"
)
...
h.Labels[headlessLabel] = headlessExists
// change the instance label
h.Labels[renameInstance] = fmt.Sprintf("%s.%s-headless", otelcol.Namespace, otelcol.Name)
Finally, you need to rebuild through the dockerfile. |
@bmbbms That seems like it would work, but I'm trying to avoid building the operator binaries myself. My current workaround has been to set However, I do agree with you that not all exporter ports should be included in the If someone could help me figure out how we collectively want these features to interact, I'd be happy to try implementing a fix. |
@yuriolisa i want to continue the convo here, because this is a bit of an odd one. I don't think we should remove the prometheus exporter port from the main collector service as is recommended here, as that may break existing users and IMO would be a bit confusing (why would the port only be exposed on the monitoring service.) I think the solution should be similar to the headless label that we add. I.e. we should add a label to the generated monitoring service that makes it clear which service the servicemonitor should be selecting. I don't think any changes are required if someone generates a podmonitor as there wouldn't be multiple potential targets. |
Can we just exclude headless services from serviceMonitor selector?
|
Component(s)
operator, collector
What happened?
Description
When defining a Prometheus Exporter named "prometheus" on an OTel Collector CRD resource, the OTel Operator (very cleverly!) adds a TCP port named "prometheus" to the
v1.Service
resources for the Collector with the same port number declared in the exporter's configuredendpoint
.The issue appears when also opting-in to creating a
ServiceMonitor
resource for the Collector by setting OpenTelemetryCollector.spec.observability.metrics.enableMetrics totrue
. WhenenableMetrics
istrue
, the Operator creates a thirdv1.Service
for the Collector with the "-monitoring" suffix. Notably, the "-monitoring"v1.Service
does not receive the named "prometheus" port. The issue is that the named port is added to both the ClusterIPv1.Service
and the "-headless"v1.Service
resource (but again, not the "-monitoring" one).When
enableMetrics
istrue
and the Collector's config specifies a Prometheus Exporter, the Operator (again, quite cleverly) adds a- port: prometheus
to the generatedServiceMonitor
's.spec.endpoints
array. ThatServiceMonitor
resource spec also bears the following selectors:which unfortunately matches all 3 of the
v1.Service
resources associated with the Collector. Since the "prometheus" named port appears on both the (unsuffixed) ClusterIPv1.Service
and the "-headless"v1.Service
, the Prometheus Operator will match both of these services and pick up the named "prometheus" port on both, causing all metrics data from the Prometheus Exporter to be scraped and stored twice (since Prometheus treats each as a distinct scrape target): once with ajob
label of "otel-collector" and again with ajob
label of "otel-collector-headless".Steps to Reproduce
Define an OTel Collector CRD as follows:
Observe that
v1.Service
+ServiceMonitor
resources are generated as shown below in the 'Actual Result' section.Expected Result
Since I'm adding the Prometheus Exporter with the intention of having those exposed metrics scraped into my Prometheus, I would much prefer for the named "prometheus" port to be added only to the "-monitoring"
v1.Service
when settingOpenTelemetryCollector.spec.observability.metrics.enableMetrics
totrue
.Actual Result
Kubernetes Version
1.25.6
Operator version
v0.86.0
Collector version
0.87.0
Environment information
There's a
monitoring.coreos.com/v1.Prometheus
CRD in my cluster from the prometheus-operator which is configured to scrape all ServiceMonitor resources in the cluster, e.g.Log output
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: