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

feat(lifecycle-operator): introduce metric showing readiness of operator #2152

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
df50087
keep
geoffrey1330 Aug 7, 2023
26989d3
keep
geoffrey1330 Sep 22, 2023
fd8436c
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 22, 2023
90a47a3
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 22, 2023
486c3be
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 22, 2023
b339a53
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 22, 2023
ee998d5
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 25, 2023
e608461
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 25, 2023
2fe56b1
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 25, 2023
ec29dc5
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 26, 2023
8733556
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 26, 2023
58a7447
Update lifecycle-operator/main.go
geoffrey1330 Sep 26, 2023
0d1deaa
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 26, 2023
3b15ec2
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 26, 2023
87d5542
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Sep 28, 2023
fd5d2bc
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Oct 3, 2023
f056a95
Add prepopulated keptn_ metrics to localhost:2222/metrics endpoint
geoffrey1330 Oct 3, 2023
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
16 changes: 16 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 @@ -49,6 +50,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel"
otelprom "go.opentelemetry.io/otel/exporters/prometheus"
metricsapi "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -95,6 +97,8 @@ type envConfig struct {
KeptnOptionsCollectorURL string `envconfig:"OTEL_COLLECTOR_URL" default:""`
}

const KeptnLifecycleActiveMetric = "keptn_lifecycle_active"

//nolint:funlen,gocognit,gocyclo
func main() {
var env envConfig
Expand All @@ -119,6 +123,14 @@ func main() {
}
provider := metric.NewMeterProvider(metric.WithReader(exporter))
meter := provider.Meter("keptn/task")

keptnLifecycleActive, err := meter.Int64Counter(KeptnLifecycleActiveMetric, metricsapi.WithDescription("signals that Keptn Lifecycle Operator is installed correctly and ready"))

if err != nil {
setupLog.Error(err, "unable to create metric "+KeptnLifecycleActiveMetric)
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 +359,10 @@ 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)
geoffrey1330 marked this conversation as resolved.
Show resolved Hide resolved
setupLog.Info("Keptn lifecycle-operator is alive")
geoffrey1330 marked this conversation as resolved.
Show resolved Hide resolved
if !disableWebhook {
webhookBuilder = webhookBuilder.SetCertificateWatcher(
certificates.NewCertificateWatcher(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands:
- script: ./check-active-metrics.sh "keptn_lifecycle_active"
validate:
assert:
- contains:
- "keptn_lifecycle_active"
12 changes: 12 additions & 0 deletions test/testmetrics/metrics/check-active-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

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

component_name=$1

metrics_url="http://lifecycle-operator-metrics-service.keptn-lifecycle-toolkit-system.svc.cluster.local:2222/metrics"

# Fetch keptn_lifecycle_active metrics
metrics=$(curl -s $metrics_url | grep "${component_name}")

echo "$metrics"
Loading