Skip to content

Commit

Permalink
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: geoffrey1330 <[email protected]>
  • Loading branch information
geoffrey1330 committed Sep 22, 2023
1 parent 26989d3 commit fd8436c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lifecycle-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -119,6 +120,14 @@ func main() {
}
provider := metric.NewMeterProvider(metric.WithReader(exporter))
meter := provider.Meter("keptn/task")

keptnLifecycleActive, err := meter.Int64Counter("keptn_lifecycle_active")

if err != nil {
setupLog.Error(err, "unable to create metric keptn_lifecycle_active")
os.Exit(1)
}

keptnMeters := telemetry.SetUpKeptnTaskMeters(meter)

// Start the prometheus HTTP server and pass the exporter Collector to it
Expand Down Expand Up @@ -347,6 +356,9 @@ func main() {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

// Set the metric value as soon as the operator starts
keptnLifecycleActive.Add(context.Background(), 1)
if !disableWebhook {
webhookBuilder = webhookBuilder.SetCertificateWatcher(
certificates.NewCertificateWatcher(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands:
- script: ./retrieve-metrics2.sh "keptn_lifecycle_active"
validate:
assert:
- contains:
- "keptn_lifecycle_active"

14 changes: 14 additions & 0 deletions test/testmetrics/metrics/retrieve-metrics2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Usage: ./retrieve-metrics.sh <component_name>

component_name=$1

# Replace with the actual URL where the metrics are exposed
metrics_url="http://localhost:2222/metrics"

# Fetch metrics for the specified component
metrics=$(curl -s $metrics_url | grep "${component_name}_active")

echo "Metrics for $component_name:"
echo "$metrics"

0 comments on commit fd8436c

Please sign in to comment.