From 69b594f47112cf99414caf0c96318d855e38d60d Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 25 Jun 2024 08:28:00 +0200 Subject: [PATCH 1/4] registration-service: new Service to `/metrics` new k8s Service to scrape the HTTP metrics from the registration service, but without exposing them to the current Route (the metrics will be exposed in a separate port in the registration service pods) see codeready-toolchain/registration-service#436 Signed-off-by: Xavier Coulon xcoulon@redhat.com --- .../toolchainconfig_controller_test.go | 4 +- .../registration-service.yaml | 82 +++++++++++++------ 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/controllers/toolchainconfig/toolchainconfig_controller_test.go b/controllers/toolchainconfig/toolchainconfig_controller_test.go index 80571f480..fe9fb828c 100644 --- a/controllers/toolchainconfig/toolchainconfig_controller_test.go +++ b/controllers/toolchainconfig/toolchainconfig_controller_test.go @@ -86,7 +86,7 @@ func TestReconcile(t *testing.T) { Exists(). HasConditions( toolchainconfig.ToSyncComplete(), - toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Service: registration-service Route: registration-service Service: api Route: api Service: proxy-metrics-service]")). + toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: registration-service-metrics Route: api Service: api Service: proxy-metrics-service]")). HasNoSyncErrors() // check member1 config @@ -274,7 +274,7 @@ func TestReconcile(t *testing.T) { Exists(). HasConditions( toolchainconfig.ToSyncFailure(), - toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Service: registration-service Route: registration-service Service: api Route: api Service: proxy-metrics-service]")). + toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: registration-service-metrics Route: api Service: api Service: proxy-metrics-service]")). HasSyncErrors(map[string]string{"missing-member": "specific member configuration exists but no matching toolchaincluster was found"}) }) }) diff --git a/deploy/registration-service/registration-service.yaml b/deploy/registration-service/registration-service.yaml index f6cf8c3a8..afb15730f 100644 --- a/deploy/registration-service/registration-service.yaml +++ b/deploy/registration-service/registration-service.yaml @@ -96,10 +96,12 @@ objects: - name: registration-service image: ${IMAGE} ports: - - containerPort: 8080 - - containerPort: 8081 - - containerPort: 8082 + - containerPort: 8080 # registration service + - containerPort: 8081 # proxy + - containerPort: 8082 # proxy metrics name: metrics + - containerPort: 8083 # registration service metrics + name: registration-service-metrics command: - registration-service imagePullPolicy: IfNotPresent @@ -140,24 +142,8 @@ objects: requests: cpu: "50m" memory: "100M" - - kind: Service - apiVersion: v1 - metadata: - name: registration-service - namespace: ${NAMESPACE} - labels: - provider: codeready-toolchain - run: registration-service - spec: - ports: - - name: "8080" - protocol: TCP - port: 80 - targetPort: 8080 - selector: - run: registration-service - type: ClusterIP - sessionAffinity: null + + # route for the registration service - kind: Route apiVersion: v1 metadata: @@ -168,6 +154,7 @@ objects: namespace: ${NAMESPACE} spec: host: '' + path: /api # we don't want to expose anything else (eg: Prometheus metrics) port: targetPort: "8080" to: @@ -177,24 +164,48 @@ objects: tls: termination: edge wildcardPolicy: None + + # service associated with the registration service route - kind: Service apiVersion: v1 metadata: - name: api + name: registration-service namespace: ${NAMESPACE} labels: provider: codeready-toolchain run: registration-service spec: ports: - - name: "8081" + - name: "8080" protocol: TCP port: 80 - targetPort: 8081 + targetPort: 8080 + selector: + run: registration-service + type: ClusterIP + sessionAffinity: null + + # internal service for the registration service, used by Prometheus to scrape the metrics + - kind: Service + apiVersion: v1 + metadata: + name: registration-service-metrics + namespace: ${NAMESPACE} + labels: + provider: codeready-toolchain + run: registration-service + spec: + ports: + - name: registration-service-metrics + protocol: TCP + port: 80 + targetPort: registration-service-metrics selector: run: registration-service type: ClusterIP sessionAffinity: null + + # route for the proxy - kind: Route apiVersion: v1 metadata: @@ -206,7 +217,6 @@ objects: name: api namespace: ${NAMESPACE} spec: - host: '' port: targetPort: "8081" to: @@ -216,6 +226,28 @@ objects: tls: termination: edge wildcardPolicy: None + + # service associated with the proxy route + - kind: Service + apiVersion: v1 + metadata: + name: api + namespace: ${NAMESPACE} + labels: + provider: codeready-toolchain + run: registration-service + spec: + ports: + - name: "8081" + protocol: TCP + port: 80 + targetPort: 8081 + selector: + run: registration-service + type: ClusterIP + sessionAffinity: null + + # internal service for the proxy, used by Prometheus to scrape the metrics - kind: Service apiVersion: v1 metadata: From 7e5849070d7a6787778a8f07e77f1a005f96b748 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 25 Jun 2024 15:35:21 +0200 Subject: [PATCH 2/4] remove unneeded change Signed-off-by: Xavier Coulon --- deploy/registration-service/registration-service.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/deploy/registration-service/registration-service.yaml b/deploy/registration-service/registration-service.yaml index afb15730f..8122fc512 100644 --- a/deploy/registration-service/registration-service.yaml +++ b/deploy/registration-service/registration-service.yaml @@ -154,7 +154,6 @@ objects: namespace: ${NAMESPACE} spec: host: '' - path: /api # we don't want to expose anything else (eg: Prometheus metrics) port: targetPort: "8080" to: From ce074250a7c6a482f8b5d6f545d525cf6c37e253 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 2 Jul 2024 09:21:40 +0200 Subject: [PATCH 3/4] shorten port name limited to 15 characters Signed-off-by: Xavier Coulon --- deploy/registration-service/registration-service.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/registration-service/registration-service.yaml b/deploy/registration-service/registration-service.yaml index 8122fc512..1b29d5132 100644 --- a/deploy/registration-service/registration-service.yaml +++ b/deploy/registration-service/registration-service.yaml @@ -101,7 +101,7 @@ objects: - containerPort: 8082 # proxy metrics name: metrics - containerPort: 8083 # registration service metrics - name: registration-service-metrics + name: regsvc-metrics command: - registration-service imagePullPolicy: IfNotPresent @@ -188,17 +188,17 @@ objects: - kind: Service apiVersion: v1 metadata: - name: registration-service-metrics + name: regsvc-metrics namespace: ${NAMESPACE} labels: provider: codeready-toolchain run: registration-service spec: ports: - - name: registration-service-metrics + - name: regsvc-metrics protocol: TCP port: 80 - targetPort: registration-service-metrics + targetPort: regsvc-metrics selector: run: registration-service type: ClusterIP From c152198b5f4b8e8ea8254be0a5625bd172cd1784 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 2 Jul 2024 09:43:02 +0200 Subject: [PATCH 4/4] fix tests Signed-off-by: Xavier Coulon --- .../toolchainconfig/toolchainconfig_controller_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/toolchainconfig/toolchainconfig_controller_test.go b/controllers/toolchainconfig/toolchainconfig_controller_test.go index fe9fb828c..f24fcd49f 100644 --- a/controllers/toolchainconfig/toolchainconfig_controller_test.go +++ b/controllers/toolchainconfig/toolchainconfig_controller_test.go @@ -86,7 +86,7 @@ func TestReconcile(t *testing.T) { Exists(). HasConditions( toolchainconfig.ToSyncComplete(), - toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: registration-service-metrics Route: api Service: api Service: proxy-metrics-service]")). + toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: regsvc-metrics Route: api Service: api Service: proxy-metrics-service]")). HasNoSyncErrors() // check member1 config @@ -274,7 +274,7 @@ func TestReconcile(t *testing.T) { Exists(). HasConditions( toolchainconfig.ToSyncFailure(), - toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: registration-service-metrics Route: api Service: api Service: proxy-metrics-service]")). + toolchainconfig.ToRegServiceDeploying("updated resources: [ServiceAccount: registration-service Role: registration-service RoleBinding: registration-service Deployment: registration-service Route: registration-service Service: registration-service Service: regsvc-metrics Route: api Service: api Service: proxy-metrics-service]")). HasSyncErrors(map[string]string{"missing-member": "specific member configuration exists but no matching toolchaincluster was found"}) }) })