diff --git a/manifests/servicemonitors.yaml b/manifests/servicemonitors.yaml index e77216af2a723cef8a4c5f468ef564625ea810f1..d47a069dd9a36b778724041a5d9dc124f9dff1cf 100644 --- a/manifests/servicemonitors.yaml +++ b/manifests/servicemonitors.yaml @@ -474,4 +474,4 @@ spec: namespaceSelector: any: false matchNames: - - tfs # namespace where the app is running \ No newline at end of file + - tfs # namespace where the app is running diff --git a/src/automation/target/kubernetes/kubernetes.yml b/src/automation/target/kubernetes/kubernetes.yml index 7aa68a257eeda04d6101f05b291882c274c43f86..fe891198dfa81668c2564c2a30fb31c8d972debe 100644 --- a/src/automation/target/kubernetes/kubernetes.yml +++ b/src/automation/target/kubernetes/kubernetes.yml @@ -28,12 +28,13 @@ metadata: name: automationservice spec: ports: - - name: http - port: 9192 - targetPort: 8080 - - name: grpc-server + - name: grpc port: 5050 targetPort: 5050 + - name: metrics + protocol: TCP + port: 9192 + targetPort: 8080 selector: app.kubernetes.io/name: automationservice type: ClusterIP @@ -95,10 +96,10 @@ spec: name: automationservice ports: - containerPort: 8080 - name: http + name: metrics protocol: TCP - containerPort: 5050 - name: grpc-server + name: grpc protocol: TCP readinessProbe: failureThreshold: 3 @@ -111,9 +112,28 @@ spec: successThreshold: 1 timeoutSeconds: 10 resources: - limits: - cpu: 500m - memory: 2048Mi requests: cpu: 50m memory: 512Mi + limits: + cpu: 500m + memory: 2048Mi +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: automationservice-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: automationservice + minReplicas: 1 + maxReplicas: 10 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 80 diff --git a/src/policy/src/main/java/eu/teraflow/policy/PolicyGatewayImpl.java b/src/policy/src/main/java/eu/teraflow/policy/PolicyGatewayImpl.java index 351b9b3512e72366c7f02e0ca14288ed6a0b7587..078262021afaaa59f3d0974d62693184537de9a0 100644 --- a/src/policy/src/main/java/eu/teraflow/policy/PolicyGatewayImpl.java +++ b/src/policy/src/main/java/eu/teraflow/policy/PolicyGatewayImpl.java @@ -20,6 +20,9 @@ import context.ContextOuterClass.ServiceId; import io.quarkus.grpc.GrpcService; import io.smallrye.mutiny.Uni; import javax.inject.Inject; +import org.eclipse.microprofile.metrics.MetricUnits; +import org.eclipse.microprofile.metrics.annotation.Counted; +import org.eclipse.microprofile.metrics.annotation.Timed; import policy.Policy; import policy.Policy.PolicyRuleBasic; import policy.Policy.PolicyRuleDevice; @@ -41,6 +44,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_policyAddService_counter") + @Timed(name = "policy_policyAddService_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleState> policyAddService(PolicyRuleService request) { final var policyRuleService = serializer.deserialize(request); @@ -51,6 +56,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_policyUpdateService_counter") + @Timed(name = "policy_policyUpdateService_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleState> policyUpdateService(PolicyRuleService request) { final var policyRuleService = serializer.deserialize(request); @@ -61,6 +68,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_policyAddDevice_counter") + @Timed(name = "policy_policyAddDevice_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleState> policyAddDevice(PolicyRuleDevice request) { final var policyRuleDevice = serializer.deserialize(request); @@ -71,6 +80,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_policyUpdateDevice_counter") + @Timed(name = "policy_policyUpdateDevice_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleState> policyUpdateDevice(PolicyRuleDevice request) { final var policyRuleDevice = serializer.deserialize(request); @@ -81,6 +92,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_policyDelete_counter") + @Timed(name = "policy_policyDelete_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleState> policyDelete(PolicyRuleId request) { final var policyRuleId = serializer.deserialize(request); @@ -88,6 +101,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_getPolicyService_counter") + @Timed(name = "policy_getPolicyService_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleService> getPolicyService(PolicyRuleId request) { final var policyRuleBasic = PolicyRuleBasic.newBuilder().setPolicyRuleId(request).build(); @@ -96,6 +111,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_getPolicyDevice_counter") + @Timed(name = "policy_getPolicyDevice_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleDevice> getPolicyDevice(PolicyRuleId request) { final var policyRuleBasic = PolicyRuleBasic.newBuilder().setPolicyRuleId(request).build(); @@ -104,6 +121,8 @@ public class PolicyGatewayImpl implements PolicyGateway { } @Override + @Counted(name = "policy_getPolicyByServiceId_counter") + @Timed(name = "policy_getPolicyByServiceId_histogram", unit = MetricUnits.MILLISECONDS) public Uni<PolicyRuleServiceList> getPolicyByServiceId(ServiceId request) { return Uni.createFrom().item(() -> Policy.PolicyRuleServiceList.newBuilder().build()); } diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml index 8416b5bcd60c4f2fee134c1db5682f7d67aea146..2596c927789d90644af3e328a527b81e4e5f53e5 100644 --- a/src/policy/target/kubernetes/kubernetes.yml +++ b/src/policy/target/kubernetes/kubernetes.yml @@ -15,12 +15,12 @@ metadata: name: policyservice spec: ports: - - name: grpc-server - port: 6060 - targetPort: 6060 - - name: http + - name: metrics port: 9192 targetPort: 8080 + - name: grpc + port: 6060 + targetPort: 6060 selector: app.kubernetes.io/name: policyservice type: ClusterIP @@ -63,12 +63,12 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - - name: MONITORING_SERVICE_HOST - value: monitoringservice - - name: CONTEXT_SERVICE_HOST - value: contextservice - name: SERVICE_SERVICE_HOST value: serviceservice + - name: CONTEXT_SERVICE_HOST + value: contextservice + - name: MONITORING_SERVICE_HOST + value: monitoringservice image: labs.etsi.org:5050/tfs/controller/policy:0.1.0 imagePullPolicy: Always livenessProbe: @@ -84,10 +84,10 @@ spec: name: policyservice ports: - containerPort: 6060 - name: grpc-server + name: grpc protocol: TCP - containerPort: 8080 - name: http + name: metrics protocol: TCP readinessProbe: failureThreshold: 3 @@ -100,9 +100,28 @@ spec: successThreshold: 1 timeoutSeconds: 10 resources: - limits: - cpu: 500m - memory: 2048Mi requests: cpu: 50m memory: 512Mi + limits: + cpu: 500m + memory: 2048Mi +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: policyservice-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: policyservice + minReplicas: 1 + maxReplicas: 10 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 80