Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARK-25280 Expose metrics for Prometheus #25

Merged
merged 3 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion LICENSE-THIRD-PARTY.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Lists of 151 third-party dependencies.
Lists of 154 third-party dependencies.
(Eclipse Public License - v 1.0) (GNU Lesser General Public License) Logback Classic Module (ch.qos.logback:logback-classic:1.2.3 - http://logback.qos.ch/logback-classic)
(Eclipse Public License - v 1.0) (GNU Lesser General Public License) Logback Core Module (ch.qos.logback:logback-core:1.2.3 - http://logback.qos.ch/logback-core)
(The Apache License, Version 2.0) spock-reports (com.athaydes:spock-reports:1.7.1 - https://github.com/renatoathaydes/spock-reports)
Expand Down Expand Up @@ -28,6 +28,9 @@ Lists of 151 third-party dependencies.
(BSD) Automaton (dk.brics.automaton:automaton:1.11-8 - http://www.brics.dk/automaton/)
(The MIT License (MIT)) ClassGraph (io.github.classgraph:classgraph:4.8.69 - https://github.com/classgraph/classgraph)
(The Apache Software License, Version 2.0) micrometer-core (io.micrometer:micrometer-core:1.5.5 - https://github.com/micrometer-metrics/micrometer)
(The Apache Software License, Version 2.0) micrometer-registry-prometheus (io.micrometer:micrometer-registry-prometheus:1.5.5 - https://github.com/micrometer-metrics/micrometer)
(The Apache Software License, Version 2.0) Prometheus Java Simpleclient (io.prometheus:simpleclient:0.8.1 - http://github.com/prometheus/client_java/simpleclient)
(The Apache Software License, Version 2.0) Prometheus Java Simpleclient Common (io.prometheus:simpleclient_common:0.8.1 - http://github.com/prometheus/client_java/simpleclient_common)
(The Apache Software License, Version 2.0) Allure Attachments (io.qameta.allure:allure-attachments:2.13.6 - https://github.com/allure-framework/allure-java)
(The Apache Software License, Version 2.0) Allure Java Commons (io.qameta.allure:allure-java-commons:2.13.6 - https://github.com/allure-framework/allure-java)
(The Apache Software License, Version 2.0) Allure JUnit Platform Integration (io.qameta.allure:allure-junit-platform:2.13.6 - https://github.com/allure-framework/allure-java)
Expand Down Expand Up @@ -149,4 +152,5 @@ Lists of 151 third-party dependencies.
(Apache 2.0) Swagger UI (org.webjars:swagger-ui:3.28.0 - http://webjars.org)
(MIT) webjars-locator-core (org.webjars:webjars-locator-core:0.45 - http://webjars.org)
(The Apache Software License, Version 2.0) org.xmlunit:xmlunit-core (org.xmlunit:xmlunit-core:2.7.0 - https://www.xmlunit.org/)
(Apache License, Version 2.0) SnakeYAML (org.yaml:snakeyaml:1.23 - http://www.snakeyaml.org)
(Apache License, Version 2.0) SnakeYAML (org.yaml:snakeyaml:1.26 - http://www.snakeyaml.org)
6 changes: 6 additions & 0 deletions appstore-metadata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lgi.appstore.metadata.api.constants;

public interface AppConstants {
String MISSING_DETAIL_VALUE = "not specified";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.lgi.appstore.metadata.model.Platform;
import com.lgi.appstore.metadata.model.StbApplicationDetails;
import com.lgi.appstore.metadata.model.StbApplicationsList;
import io.micrometer.core.annotation.Timed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.lgi.appstore.metadata.config;

import com.lgi.appstore.metadata.info.AppProperty;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Optional;

import static com.lgi.appstore.metadata.api.constants.AppConstants.MISSING_DETAIL_VALUE;

@Component
public class MeterRegistryConfig {
private final Environment environment;

public MeterRegistryConfig(final Environment environment) {
this.environment = environment;
}

@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry
.config()
.commonTags("application", getAppNameFromEnvironment());
}

private String getAppNameFromEnvironment() {
return Optional.ofNullable(environment.getProperty(AppProperty.APP_NAME.toString()))
.orElse(MISSING_DETAIL_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import java.util.Optional;
import java.util.TimeZone;

import static com.lgi.appstore.metadata.api.constants.AppConstants.MISSING_DETAIL_VALUE;

@Component
public class AppInfoContributor implements InfoContributor {

private static final String MISSING_DETAIL_VALUE = "not specified";
private static final Map<String, Object> DETAILS = new HashMap<>();

private final Environment environment;
Expand Down Expand Up @@ -70,7 +70,7 @@ private void addAppPropertyDetail(AppProperty appProperty, Object value) {
DETAILS.put(appProperty.toString(), value);
}

private Object getAppPropertyValueFromEnvironment(AppProperty appProperty) {
private Object getAppPropertyValueFromEnvironment(final AppProperty appProperty) {
return Optional.ofNullable(environment.getProperty(appProperty.toString()))
.orElse(MISSING_DETAIL_VALUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ management.endpoints.jmx.exposure.exclude=info
management.endpoints.web.base-path=
management.endpoint.info.enabled=true
management.info.defaults.enabled=false
management.endpoints.web.exposure.include=info,prometheus
management.endpoint.prometheus.enabled=${PROMETHEUS_METRICS:false}
management.metrics.web.server.request.autotime.enabled=true
server.tomcat.mbeanregistry.enabled=true