Search in sources :

Example 1 with WithPrometheus

use of com.redhat.service.smartevents.shard.operator.WithPrometheus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ServiceMonitorServiceTest method fetchOrCreateServiceMonitor.

@Test
@WithPrometheus
void fetchOrCreateServiceMonitor() {
    // Given
    final BridgeDTO bridge = TestSupport.newAvailableBridgeDTO();
    final BridgeIngress bridgeIngress = BridgeIngress.fromDTO(bridge, "default", TestSupport.INGRESS_IMAGE);
    final Secret secretMock = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(bridgeIngress.getMetadata().getName()).build()).build();
    final Deployment deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(bridgeIngress, secretMock);
    final Service service = bridgeIngressService.fetchOrCreateBridgeIngressService(bridgeIngress, deployment);
    // When
    final Optional<ServiceMonitor> serviceMonitor = serviceMonitorService.fetchOrCreateServiceMonitor(bridgeIngress, service, "ingress");
    // Then
    assertThat(serviceMonitor).isPresent();
    // check: https://prometheus-operator.dev/docs/operator/troubleshooting/#overview-of-servicemonitor-tagging-and-related-elements
    assertThat(serviceMonitor.get().getSpec().getSelector().getMatchLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.MANAGED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.CREATED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.COMPONENT_LABEL, "ingress");
    assertThat(service.getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
}
Also used : BridgeIngress(com.redhat.service.smartevents.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) ServiceMonitor(io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) BridgeIngressService(com.redhat.service.smartevents.shard.operator.BridgeIngressService) Service(io.fabric8.kubernetes.api.model.Service) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) WithPrometheus(com.redhat.service.smartevents.shard.operator.WithPrometheus)

Aggregations

BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)1 BridgeIngressService (com.redhat.service.smartevents.shard.operator.BridgeIngressService)1 WithPrometheus (com.redhat.service.smartevents.shard.operator.WithPrometheus)1 BridgeIngress (com.redhat.service.smartevents.shard.operator.resources.BridgeIngress)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)1 Service (io.fabric8.kubernetes.api.model.Service)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 ServiceMonitor (io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 Test (org.junit.jupiter.api.Test)1