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 cb9f891  Activate the Prometheus Java agent according to the eponym 
trait configuration
cb9f891 is described below

commit cb9f8911666ceb40d83135aea5828ce09d89eb96
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Thu Jan 24 10:22:10 2019 +0100

    Activate the Prometheus Java agent according to the eponym trait 
configuration
---
 pkg/trait/catalog.go    |  6 ++++--
 pkg/trait/prometheus.go | 21 +++++++++++++++------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/pkg/trait/catalog.go b/pkg/trait/catalog.go
index b5f3fa7..763aebd 100644
--- a/pkg/trait/catalog.go
+++ b/pkg/trait/catalog.go
@@ -104,6 +104,8 @@ func (c *Catalog) allTraits() []Trait {
        }
 }
 
+// Traits may depend on the result of previously executed ones,
+// so care must be taken while changing the lists order.
 func (c *Catalog) traitsFor(environment *Environment) []Trait {
        switch environment.DetermineProfile() {
        case v1alpha1.TraitProfileOpenShift:
@@ -116,10 +118,10 @@ func (c *Catalog) traitsFor(environment *Environment) 
[]Trait {
                        c.tEnvironment,
                        c.tClasspath,
                        c.tSpringBoot,
+                       c.tPrometheus,
                        c.tDeployment,
                        c.tService,
                        c.tRoute,
-                       c.tPrometheus,
                        c.tOwner,
                }
        case v1alpha1.TraitProfileKubernetes:
@@ -132,10 +134,10 @@ func (c *Catalog) traitsFor(environment *Environment) 
[]Trait {
                        c.tEnvironment,
                        c.tClasspath,
                        c.tSpringBoot,
+                       c.tPrometheus,
                        c.tDeployment,
                        c.tService,
                        c.tIngress,
-                       c.tPrometheus,
                        c.tOwner,
                }
        case v1alpha1.TraitProfileKnative:
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index 08efd88..56e64b9 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -19,9 +19,12 @@ package trait
 
 import (
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-       monitoringv1 
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
+       "github.com/apache/camel-k/pkg/util/envvar"
+
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+       monitoringv1 
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
 )
 
 type prometheusTrait struct {
@@ -30,6 +33,8 @@ type prometheusTrait struct {
        Port int `property:"port"`
 }
 
+// The Prometheus trait must be executed prior to the deployment trait
+// as it mutates environment variables
 func newPrometheusTrait() *prometheusTrait {
        return &prometheusTrait{
                BaseTrait: BaseTrait{
@@ -40,15 +45,19 @@ func newPrometheusTrait() *prometheusTrait {
 }
 
 func (t *prometheusTrait) Configure(e *Environment) (bool, error) {
-       if t.Enabled == nil || !*t.Enabled {
-               return false, nil
+       enabled := false
+
+       if e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying) && 
t.Enabled != nil && *t.Enabled {
+               enabled = true
        }
 
-       if !e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying) {
-               return false, nil
+       // Deactivate the Prometheus Java agent accordingly
+       // Note: the AB_PROMETHEUS_OFF environment variable acts as an option 
flag
+       if !enabled {
+               envvar.SetVal(&e.EnvVars, "AB_PROMETHEUS_OFF", "true")
        }
 
-       return true, nil
+       return enabled, nil
 }
 
 func (t *prometheusTrait) Apply(e *Environment) (err error) {

Reply via email to