You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/01/29 11:03:25 UTC
[camel-k] branch master updated: Add Prometheus ServiceMonitor
labels trait configuration
This is an automated email from the ASF dual-hosted git repository.
nferraro 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 e9c4932 Add Prometheus ServiceMonitor labels trait configuration
e9c4932 is described below
commit e9c493251659ddd884b24013a224d1d6a4a86163
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 29 10:41:15 2019 +0100
Add Prometheus ServiceMonitor labels trait configuration
---
docs/traits.adoc | 14 +++++++++-----
pkg/trait/prometheus.go | 20 +++++++++++++++-----
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/docs/traits.adoc b/docs/traits.adoc
index 338272c..60456cb 100644
--- a/docs/traits.adoc
+++ b/docs/traits.adoc
@@ -177,16 +177,20 @@ The following is a list of common traits that can be configured by the end users
| prometheus
| Kubernetes, OpenShift
-| Exposes the integration with a Service and a ServiceMonitor resources so that the Prometheus endpoint can be scraped.
- +
- +
- It's disabled by default.
+| 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.
+
+It's disabled by default.
[cols="m,"]
!===
+! prometheus.labels
+! The `ServiceMonitor` resource labels.
+
! prometheus.port
-! To configure a different Prometheus endpoint port (default `9778`).
+! The Prometheus endpoint port (default `9778`).
!===
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 3ee31e9..7a4d7be 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -18,6 +18,7 @@ limitations under the License.
package trait
import (
+ "strings"
"strconv"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
@@ -33,6 +34,7 @@ import (
type prometheusTrait struct {
BaseTrait `property:",squash"`
+ Labels string `property:"labels"`
Port int `property:"port"`
}
@@ -107,6 +109,9 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
}
func (t *prometheusTrait) getServiceMonitorFor(e *Environment) *monitoringv1.ServiceMonitor {
+ labels := parseLabels(t.Labels)
+ labels["camel.apache.org/integration"] = e.Integration.Name
+
smt := monitoringv1.ServiceMonitor{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceMonitor",
@@ -115,11 +120,7 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) *monitoringv1.Ser
ObjectMeta: metav1.ObjectMeta{
Name: e.Integration.Name,
Namespace: e.Integration.Namespace,
- Labels: map[string]string{
- // TODO: add the ability to configure additional labels
- "camel.apache.org/integration": e.Integration.Name,
- "team": "fuse",
- },
+ Labels: labels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Selector: metav1.LabelSelector{
@@ -136,3 +137,12 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) *monitoringv1.Ser
}
return &smt
}
+
+func parseLabels(labels string) map[string]string {
+ m := make(map[string]string)
+ for _, label := range strings.Split(labels, ",") {
+ kv := strings.Split(label, "=")
+ m[kv[0]] = kv[1]
+ }
+ return m
+}