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

Fix #1384: allow to define an alternative prometheus config #1397

Merged
merged 1 commit into from
Apr 8, 2020
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
6 changes: 0 additions & 6 deletions docs/modules/ROOT/pages/traits/container.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ The following configuration options are available:
| bool
| ProbesEnabled enable/disable probes on the container (default `false`)

| container.probe-port
| int
| ProbePort configures the port on which the probes are exposed, by default it inhierit the
value from the `http` port configured on the container. Note that the value has no effect for Knative service
as the port should be the same as the port declared by the container.

| container.probe-path
| string
| Path to access on the probe ( default `/health`). Note that this property is not supported
Expand Down
1 change: 0 additions & 1 deletion docs/modules/ROOT/pages/traits/cron.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ while `35m` or `50s` cannot).
|===

// End of autogenerated code - DO NOT EDIT! (configuration)

7 changes: 6 additions & 1 deletion docs/modules/ROOT/pages/traits/prometheus.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following configuration options are available:

| prometheus.port
| int
| The Prometheus endpoint port (default `9778`).
| The Prometheus endpoint port (default `9779`).

| prometheus.service-monitor
| bool
Expand All @@ -43,6 +43,11 @@ The following configuration options are available:
| string
| The `ServiceMonitor` resource labels, applicable when `service-monitor` is `true`.

| prometheus.configmap
| string
| To use a custom ConfigMap containing the Prometheus exporter configuration (under the `content` ConfigMap key). When this property is left empty (default),
Camel K generates a standard Prometheus configuration for the integration.

|===

// End of autogenerated code - DO NOT EDIT! (configuration)
28 changes: 19 additions & 9 deletions pkg/trait/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ import (
// +camel-k:trait=prometheus
type prometheusTrait struct {
BaseTrait `property:",squash"`
// The Prometheus endpoint port (default `9778`).
// The Prometheus endpoint port (default `9779`).
Port int `property:"port"`
// Whether a `ServiceMonitor` resource is created (default `true`).
ServiceMonitor bool `property:"service-monitor"`
// The `ServiceMonitor` resource labels, applicable when `service-monitor` is `true`.
ServiceMonitorLabels string `property:"service-monitor-labels"`
// To use a custom ConfigMap containing the Prometheus exporter configuration (under the `content` ConfigMap key). When this property is left empty (default),
// Camel K generates a standard Prometheus configuration for the integration.
ConfigMap string `property:"configmap"`
}

const (
Expand Down Expand Up @@ -83,15 +86,14 @@ func (t *prometheusTrait) Apply(e *Environment) (err error) {
// TODO: We may want to make the Prometheus version configurable
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, "mvn:io.prometheus.jmx/jmx_prometheus_javaagent:0.3.1")

// Add the default Prometheus JMX exporter configuration
// TODO: Support user-provided configuration
configMap := t.getJmxExporterConfigMap(e)
e.Resources.Add(configMap)
// Use the provided configuration or add the default Prometheus JMX exporter configuration
configMapName := t.getJmxExporterConfigMapOrAdd(e)

e.Integration.Status.AddOrReplaceGeneratedResources(v1.ResourceSpec{
Type: v1.ResourceTypeData,
DataSpec: v1.DataSpec{
Name: prometheusJmxExporterConfigFileName,
ContentRef: configMap.Name,
ContentRef: configMapName,
},
MountPath: prometheusJmxExporterConfigMountPath,
})
Expand Down Expand Up @@ -216,14 +218,20 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) (*monitoringv1.Se
return &smt, nil
}

func (t *prometheusTrait) getJmxExporterConfigMap(e *Environment) *corev1.ConfigMap {
return &corev1.ConfigMap{
func (t *prometheusTrait) getJmxExporterConfigMapOrAdd(e *Environment) string {
if t.ConfigMap != "" {
return t.ConfigMap
}

// Add a default config if not specified by the user
defaultName := e.Integration.Name + "-prometheus"
cm := corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: e.Integration.Name + "-prometheus",
Name: defaultName,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
"camel.apache.org/integration": e.Integration.Name,
Expand All @@ -233,4 +241,6 @@ func (t *prometheusTrait) getJmxExporterConfigMap(e *Environment) *corev1.Config
"content": deploy.ResourceAsString("/prometheus-jmx-exporter.yaml"),
},
}
e.Resources.Add(&cm)
return defaultName
}