Skip to content
Permalink
Browse files
GERONIMO-6650 extract common logic in a common module
  • Loading branch information
rmannibucau committed Oct 19, 2018
1 parent 62f6023 commit 1d2dc45448e9504d75f57f40704e61bb5dff24a6
Showing 24 changed files with 267 additions and 138 deletions.
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>geronimo-metrics-parent</artifactId>
<groupId>org.apache.geronimo</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>geronimo-metrics-common</artifactId>
<name>Geronimo Metrics :: Common</name>

<properties>
<geronimo-metrics.Automatic-Module-Name>org.apache.geronimo.microprofile.metrics.common</geronimo-metrics.Automatic-Module-Name>
</properties>
</project>
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import static java.lang.String.format;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import java.util.concurrent.atomic.LongAdder;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import java.io.IOException;
import java.io.OutputStream;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import static java.util.stream.Collectors.toMap;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.impl;
package org.apache.geronimo.microprofile.metrics.common;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@@ -24,7 +24,6 @@

import org.eclipse.microprofile.metrics.Histogram;
import org.eclipse.microprofile.metrics.Meter;
import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.Snapshot;
import org.eclipse.microprofile.metrics.Timer;

@@ -14,22 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.jaxrs;
package org.apache.geronimo.microprofile.metrics.common.jaxrs;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
import static org.eclipse.microprofile.metrics.MetricRegistry.Type.BASE;
import static org.eclipse.microprofile.metrics.MetricRegistry.Type.VENDOR;

import java.util.Collections;
import java.util.Map;
import java.util.stream.Stream;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.OPTIONS;
import javax.ws.rs.Path;
@@ -39,29 +35,32 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.geronimo.microprofile.metrics.common.prometheus.PrometheusFormatter;
import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.Gauge;
import org.eclipse.microprofile.metrics.Metadata;
import org.eclipse.microprofile.metrics.Metric;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.annotation.RegistryType;

@Path("metrics")
@ApplicationScoped
public class MetricsEndpoints {
@Inject
@RegistryType(type = BASE)
private MetricRegistry baseRegistry;

@Inject
@RegistryType(type = VENDOR)
private MetricRegistry vendorRegistry;

@Inject
private MetricRegistry applicationRegistry;

@Inject
private PrometheusFormatter prometheus;
private final PrometheusFormatter prometheus = new PrometheusFormatter();

public void setBaseRegistry(final MetricRegistry baseRegistry) {
this.baseRegistry = baseRegistry;
}

public void setVendorRegistry(final MetricRegistry vendorRegistry) {
this.vendorRegistry = vendorRegistry;
}

public void setApplicationRegistry(final MetricRegistry applicationRegistry) {
this.applicationRegistry = applicationRegistry;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.metrics.jaxrs;
package org.apache.geronimo.microprofile.metrics.common.prometheus;

import static java.lang.Math.pow;
import static java.util.Collections.singletonMap;
@@ -26,8 +26,6 @@
import java.util.function.Function;
import java.util.stream.Stream;

import javax.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.Gauge;
import org.eclipse.microprofile.metrics.Histogram;
@@ -42,7 +40,6 @@
// this is so weird to have this format built-in but not mainstream ones,
// todo: pby make it dropped from the spec
// note: this is a simplified serialization flavor and it can need some more love
@ApplicationScoped
public class PrometheusFormatter {
public StringBuilder toText(final MetricRegistry registry,
final String registryKey,
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>geronimo-metrics-parent</artifactId>
<groupId>org.apache.geronimo</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>geronimo-metrics</artifactId>

<properties>
<geronimo-metrics.Automatic-Module-Name>org.apache.geronimo.microprofile.metrics
</geronimo-metrics.Automatic-Module-Name>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.geronimo</groupId>
<artifactId>geronimo-metrics-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.meecrowave</groupId>
<artifactId>meecrowave-arquillian</artifactId>
<version>1.2.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.metrics</groupId>
<artifactId>microprofile-metrics-api-tck</artifactId>
<version>${spec.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.metrics</groupId>
<artifactId>microprofile-metrics-rest-tck</artifactId>
<version>${spec.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.config</groupId>
<artifactId>geronimo-config-impl</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<reuseForks>false</reuseForks>
<dependenciesToScan>
<dependency>org.eclipse.microprofile.metrics:microprofile-metrics-api-tck</dependency>
<dependency>org.eclipse.microprofile.metrics:microprofile-metrics-rest-tck</dependency>
</dependenciesToScan>
<environmentVariables>
<MP_METRICS_TAGS>tier=integration</MP_METRICS_TAGS>
</environmentVariables>
<systemPropertyVariables>
<geronimo.metrics.jaxrs.activated>true</geronimo.metrics.jaxrs.activated>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -20,7 +20,6 @@
import static java.util.Optional.ofNullable;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -58,10 +57,10 @@
import javax.enterprise.util.AnnotationLiteral;
import javax.enterprise.util.Nonbinding;

import org.apache.geronimo.microprofile.metrics.impl.BaseMetrics;
import org.apache.geronimo.microprofile.metrics.impl.GaugeImpl;
import org.apache.geronimo.microprofile.metrics.impl.RegistryImpl;
import org.apache.geronimo.microprofile.metrics.jaxrs.MetricsEndpoints;
import org.apache.geronimo.microprofile.metrics.common.BaseMetrics;
import org.apache.geronimo.microprofile.metrics.common.GaugeImpl;
import org.apache.geronimo.microprofile.metrics.common.RegistryImpl;
import org.apache.geronimo.microprofile.metrics.jaxrs.CdiMetricsEndpoints;
import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.Gauge;
import org.eclipse.microprofile.metrics.Histogram;
@@ -77,8 +76,6 @@
import org.eclipse.microprofile.metrics.annotation.Timed;

public class MetricsExtension implements Extension {
private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];

private final MetricRegistry applicationRegistry = new RegistryImpl();
private final MetricRegistry baseRegistry = new RegistryImpl();
private final MetricRegistry vendorRegistry = new RegistryImpl();
@@ -88,7 +85,7 @@ public class MetricsExtension implements Extension {
private final Collection<Runnable> producersRegistrations = new ArrayList<>();
private final Collection<CreationalContext<?>> creationalContexts = new ArrayList<>();

void letOtherExtensionsUseRegistries(@Observes final ProcessAnnotatedType<MetricsEndpoints> processAnnotatedType) {
void letOtherExtensionsUseRegistries(@Observes final ProcessAnnotatedType<CdiMetricsEndpoints> processAnnotatedType) {
if (!Boolean.getBoolean("geronimo.metrics.jaxrs.activated")) {
processAnnotatedType.veto();
}

0 comments on commit 1d2dc45

Please sign in to comment.