Skip to content

Commit

Permalink
fix(metrics-operator): use correct port for serving metrics api (#954)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl authored Mar 6, 2023
1 parent bd49357 commit d29ab64
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion metrics-operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ spec:
name: webhook-server
protocol: TCP
- name: metrics
containerPort: 2222
containerPort: 9999
protocol: TCP
- name: custom-metrics
containerPort: 6443
Expand Down
2 changes: 1 addition & 1 deletion metrics-operator/config/manager/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
port: 443
- name: metrics
protocol: TCP
port: 2222
port: 9999
targetPort: metrics
selector:
control-plane: metrics-operator
17 changes: 0 additions & 17 deletions metrics-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
Expand All @@ -36,7 +34,6 @@ import (
metricscontroller "github.com/keptn/lifecycle-toolkit/metrics-operator/controllers/metrics"
keptnserver "github.com/keptn/lifecycle-toolkit/metrics-operator/pkg/metrics"
"github.com/open-feature/go-sdk/pkg/openfeature"
"github.com/prometheus/client_golang/prometheus/promhttp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -92,9 +89,6 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Start the prometheus HTTP server and pass the exporter Collector to it
go serveMetrics()

// Start the custom metrics adapter
go startCustomMetricsAdapter(env.PodNamespace)

Expand Down Expand Up @@ -177,17 +171,6 @@ func main() {
}
}

func serveMetrics() {
log.Printf("serving metrics at localhost:2222/metrics")

http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2222", nil)
if err != nil {
fmt.Printf("error serving http: %v", err)
return
}
}

func startCustomMetricsAdapter(namespace string) {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer cancel()
Expand Down
3 changes: 2 additions & 1 deletion metrics-operator/pkg/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (m *serverManager) setup() error {
klog.Infof("Keptn Metrics server enabled: %v", serverEnabled)

if serverEnabled && m.server == nil {
klog.Infof("serving metrics at localhost:9999/metrics")
klog.Infof("serving Prometheus metrics at localhost:9999/metrics")
klog.Infof("serving KeptnMetrics at localhost:9999/api/v1/metrics/{namespace}/{metric}")

router := mux.NewRouter()
router.Path("/metrics").Handler(promhttp.Handler())
Expand Down
15 changes: 13 additions & 2 deletions test/integration/expose-keptn-metric/00-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ spec:
template:
spec:
containers:
- name: test
- name: test-prometheus
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:2222/metrics > ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
then
exit 1
fi
- name: test-api-endpoint
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics//keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
then
exit 1
fi
restartPolicy: Never
16 changes: 14 additions & 2 deletions test/integration/expose-keptn-metric/01-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@ spec:
template:
spec:
containers:
- name: test
- name: test-prometheus
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:2222/metrics > ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
then
exit 0
fi
exit 1
- name: test-api-endpoint
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/keptn-lifecycle-toolkit-system/keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
then
exit 0
fi
exit 1
restartPolicy: Never

0 comments on commit d29ab64

Please sign in to comment.