@Test public void testNoDefinedPrometheusPort() throws Exception { final ProcessorConfig config = new ProcessorConfig( null, null, Collections.singletonMap( PrometheusEnricher.ENRICHER_NAME, new TreeMap() ) ); final BuildConfiguration imageConfig = new BuildConfiguration.Builder() .build(); new Expectations() {{ context.getConfiguration(); result = new Configuration.Builder() .processorConfig(config) .images(Arrays.asList(imageConfiguration)) .build(); imageConfiguration.getBuildConfiguration(); result = imageConfig; }}; KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new ServiceBuilder().withNewMetadata().withName("foo").endMetadata().build()); PrometheusEnricher enricher = new PrometheusEnricher(context); enricher.create(PlatformMode.kubernetes, builder); Map<String, String> annotations = builder.buildFirstItem().getMetadata().getAnnotations(); assertEquals(Collections.emptyMap(), annotations); }
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { log.verbose("Add prometheus.io annotations: %s=%s, %s=%s", ANNOTATION_PROMETHEUS_SCRAPE, "true", ANNOTATION_PROMETHEUS_PORT, prometheusPort); Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); }
PrometheusEnricher extends BaseEnricher { @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { log.verbose("Add prometheus.io annotations: %s=%s, %s=%s", ANNOTATION_PROMETHEUS_SCRAPE, "true", ANNOTATION_PROMETHEUS_PORT, prometheusPort); Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); } }
PrometheusEnricher extends BaseEnricher { @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { log.verbose("Add prometheus.io annotations: %s=%s, %s=%s", ANNOTATION_PROMETHEUS_SCRAPE, "true", ANNOTATION_PROMETHEUS_PORT, prometheusPort); Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); } PrometheusEnricher(MavenEnricherContext buildContext); }
PrometheusEnricher extends BaseEnricher { @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { log.verbose("Add prometheus.io annotations: %s=%s, %s=%s", ANNOTATION_PROMETHEUS_SCRAPE, "true", ANNOTATION_PROMETHEUS_PORT, prometheusPort); Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); } PrometheusEnricher(MavenEnricherContext buildContext); @Override void create(PlatformMode platformMode, KubernetesListBuilder builder); }
PrometheusEnricher extends BaseEnricher { @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { log.verbose("Add prometheus.io annotations: %s=%s, %s=%s", ANNOTATION_PROMETHEUS_SCRAPE, "true", ANNOTATION_PROMETHEUS_PORT, prometheusPort); Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); } PrometheusEnricher(MavenEnricherContext buildContext); @Override void create(PlatformMode platformMode, KubernetesListBuilder builder);  }