This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 0176e135c1e1bcf5cce960e1cf3fca23610d59b9 Author: Antonin Stefanutti <[email protected]> AuthorDate: Fri Aug 27 11:37:16 2021 +0200 feat(native): Add type label to build metrics --- e2e/common/operator_metrics_test.go | 5 +++++ pkg/controller/build/metrics.go | 24 ++++++++++++++++++++---- pkg/controller/build/schedule.go | 3 +-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/e2e/common/operator_metrics_test.go b/e2e/common/operator_metrics_test.go index abb92b3..dc10029 100644 --- a/e2e/common/operator_metrics_test.go +++ b/e2e/common/operator_metrics_test.go @@ -115,6 +115,7 @@ func TestMetrics(t *testing.T) { { Label: []*prometheus.LabelPair{ label("result", "Succeeded"), + label("type", "fast-jar"), }, Histogram: &prometheus.Histogram{ SampleCount: uint64P(1), @@ -151,6 +152,7 @@ func TestMetrics(t *testing.T) { { Label: []*prometheus.LabelPair{ label("result", "Succeeded"), + label("type", "fast-jar"), }, Histogram: &prometheus.Histogram{ SampleCount: uint64P(1), @@ -367,6 +369,9 @@ func TestMetrics(t *testing.T) { Type: metricTypeP(prometheus.MetricType_HISTOGRAM), Metric: []*prometheus.Metric{ { + Label: []*prometheus.LabelPair{ + label("type", "fast-jar"), + }, Histogram: &prometheus.Histogram{ SampleCount: uint64P(1), SampleSum: histogram.SampleSum, diff --git a/pkg/controller/build/metrics.go b/pkg/controller/build/metrics.go index 16fd330..387f117 100644 --- a/pkg/controller/build/metrics.go +++ b/pkg/controller/build/metrics.go @@ -28,7 +28,10 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" ) -const buildResultLabel = "result" +const ( + buildResultLabel = "result" + buildTypeLabel = "type" +) var ( buildDuration = prometheus.NewHistogramVec( @@ -46,6 +49,7 @@ var ( }, []string{ buildResultLabel, + buildTypeLabel, }, ) @@ -57,10 +61,11 @@ var ( }, []string{ buildResultLabel, + buildTypeLabel, }, ) - queueDuration = prometheus.NewHistogram( + queueDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "camel_k_build_queue_duration_seconds", Help: "Camel K build queue duration", @@ -72,6 +77,9 @@ var ( 5 * time.Minute.Seconds(), }, }, + []string{ + buildTypeLabel, + }, ) ) @@ -80,6 +88,11 @@ func init() { metrics.Registry.MustRegister(buildDuration, buildRecovery, queueDuration) } +func observeBuildQueueDuration(build *v1.Build) { + queueDuration.WithLabelValues(build.Labels[v1.IntegrationKitLayoutLabel]). + Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds()) +} + func observeBuildResult(build *v1.Build, phase v1.BuildPhase, duration time.Duration) { attempt, attemptMax := getBuildAttemptFor(build) @@ -89,8 +102,11 @@ func observeBuildResult(build *v1.Build, phase v1.BuildPhase, duration time.Dura phase = v1.BuildPhaseError } - buildRecovery.WithLabelValues(phase.String()).Observe(float64(attempt)) - buildDuration.WithLabelValues(phase.String()).Observe(duration.Seconds()) + resultLabel := phase.String() + typeLabel := build.Labels[v1.IntegrationKitLayoutLabel] + + buildRecovery.WithLabelValues(resultLabel, typeLabel).Observe(float64(attempt)) + buildDuration.WithLabelValues(resultLabel, typeLabel).Observe(duration.Seconds()) } func getBuildAttemptFor(build *v1.Build) (int, int) { diff --git a/pkg/controller/build/schedule.go b/pkg/controller/build/schedule.go index c49b904..93cffd9 100644 --- a/pkg/controller/build/schedule.go +++ b/pkg/controller/build/schedule.go @@ -20,7 +20,6 @@ package build import ( "context" "sync" - "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -119,7 +118,7 @@ func (action *scheduleAction) toPendingPhase(ctx context.Context, build *v1.Buil } // Report the duration the Build has been waiting in the build queue - queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds()) + observeBuildQueueDuration(build) return nil }
