You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/02/01 16:04:19 UTC
[camel-k] branch master updated: Add an option to deactivate
ServiceMonitor resource creation in Prometheus trait
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new 9dccf73 Add an option to deactivate ServiceMonitor resource creation in Prometheus trait
9dccf73 is described below
commit 9dccf73ae4ec5cab9c26ea0a7b1122fd75dd08ac
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Feb 1 15:44:17 2019 +0100
Add an option to deactivate ServiceMonitor resource creation in Prometheus trait
---
docs/traits.adoc | 12 ++++++++----
pkg/trait/prometheus.go | 24 ++++++++++++++----------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/docs/traits.adoc b/docs/traits.adoc
index 76b36ed..3a6a0f3 100644
--- a/docs/traits.adoc
+++ b/docs/traits.adoc
@@ -200,19 +200,23 @@ The following is a list of common traits that can be configured by the end users
| Kubernetes, OpenShift
| Exposes the integration with a `Service` and a `ServiceMonitor` resources so that the Prometheus endpoint can be scraped.
-WARNING: It requires the https://github.com/coreos/prometheus-operator[Prometheus Operator] custom resource definitions to be installed.
+WARNING: Creating the `ServiceMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus Operator] custom resource definition to be installed.
+You can set `service-monitor` to `false` for the Prometheus trait to work without the Prometheus operator.
It's disabled by default.
[cols="m,"]
!===
-! prometheus.labels
-! The `ServiceMonitor` resource labels.
-
! prometheus.port
! The Prometheus endpoint port (default `9778`).
+! prometheus.service-monitor
+! Whether a `ServiceMonitor` resource is created (default `true`).
+
+! prometheus.service-monitor-labels
+! The `ServiceMonitor` resource labels, applicable when `service-monitor` is `true`.
+
!===
|=======================
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index eedf7f4..d05cb7f 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -34,8 +34,9 @@ import (
type prometheusTrait struct {
BaseTrait `property:",squash"`
- Labels string `property:"labels"`
- Port int `property:"port"`
+ Port int `property:"port"`
+ ServiceMonitor bool `property:"service-monitor"`
+ ServiceMonitorLabels string `property:"service-monitor-labels"`
}
const prometheusPortName = "prometheus"
@@ -47,7 +48,8 @@ func newPrometheusTrait() *prometheusTrait {
BaseTrait: BaseTrait{
id: ID("prometheus"),
},
- Port: 9779,
+ Port: 9779,
+ ServiceMonitor: true,
}
}
@@ -99,23 +101,25 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
Protocol: corev1.ProtocolTCP,
})
} else {
- return errors.New("Cannot add Prometheus container port: no integration container")
+ return errors.New("cannot add Prometheus container port: no integration container")
}
return nil
})
- // Add the ServiceMonitor resource
- smt, err := t.getServiceMonitorFor(e)
- if err != nil {
- return err
+ if t.ServiceMonitor {
+ // Add the ServiceMonitor resource
+ smt, err := t.getServiceMonitorFor(e)
+ if err != nil {
+ return err
+ }
+ e.Resources.Add(smt)
}
- e.Resources.Add(smt)
return nil
}
func (t *prometheusTrait) getServiceMonitorFor(e *Environment) (*monitoringv1.ServiceMonitor, error) {
- labels, err := parseCsvMap(&t.Labels)
+ labels, err := parseCsvMap(&t.ServiceMonitorLabels)
if err != nil {
return nil, err
}