Skip to content

Commit a899e54

Browse files
authored
[ISSUE #3430] Refactor eventmesh-metrics-prometheus module (#4840)
* [ISSUE #3430]Refactor eventmesh-metrics-prometheus module * optimize code * optimize code
1 parent 1fdb5b2 commit a899e54

File tree

100 files changed

+4610
-1839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4610
-1839
lines changed

Diff for: build.gradle

+7-9
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,13 @@ subprojects {
481481
dependency "io.dropwizard.metrics:metrics-annotation:4.1.0"
482482
dependency "io.dropwizard.metrics:metrics-json:4.1.0"
483483

484-
dependency 'io.opentelemetry:opentelemetry-api:1.3.0'
485-
dependency 'io.opentelemetry:opentelemetry-sdk:1.3.0'
486-
dependency 'io.opentelemetry:opentelemetry-sdk-metrics:1.3.0-alpha'
487-
dependency 'io.opentelemetry:opentelemetry-exporter-prometheus:1.3.0-alpha'
488-
dependency 'io.prometheus:simpleclient:0.8.1'
489-
dependency 'io.prometheus:simpleclient_httpserver:0.8.1'
490-
dependency 'io.opentelemetry:opentelemetry-exporter-zipkin:1.3.0'
491-
dependency 'io.opentelemetry:opentelemetry-semconv:1.3.0-alpha'
492-
dependency 'io.opentelemetry:opentelemetry-exporter-jaeger:1.4.0'
484+
dependency 'io.opentelemetry:opentelemetry-api:1.36.0'
485+
dependency 'io.opentelemetry:opentelemetry-sdk:1.36.0'
486+
dependency 'io.opentelemetry:opentelemetry-sdk-metrics:1.36.0'
487+
dependency 'io.opentelemetry:opentelemetry-exporter-prometheus:1.36.0-alpha'
488+
dependency 'io.opentelemetry:opentelemetry-exporter-zipkin:1.36.0'
489+
dependency 'io.opentelemetry:opentelemetry-semconv:1.30.1-alpha'
490+
dependency 'io.opentelemetry:opentelemetry-exporter-jaeger:1.34.1'
493491

494492
dependency "io.openmessaging:openmessaging-api:2.2.1-pubsub"
495493

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.common;
19+
20+
21+
public class MetricsConstants {
22+
23+
private MetricsConstants() {
24+
25+
}
26+
27+
public static final String UNKOWN = "unkown";
28+
29+
public static final String LABEL_PROCESSOR = "processor";
30+
31+
public static final String CLIENT_ADDRESS = "client.address";
32+
33+
public static final String RPC_SYSTEM = "rpc.system";
34+
35+
public static final String RPC_SERVICE = "rpc.service";
36+
37+
//GRPC-https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/rpc-metrics/
38+
public static final String GRPC_NET_PEER_PORT = "net.peer.port";
39+
40+
public static final String GRPC_NET_PEER_NAME = "net.peer.name";
41+
42+
public static final String GRPC_NET_SOCK_PEER_ADDR = "net.sock.peer.addr";
43+
44+
public static final String GRPC_NET_SOCK_PEER_PORT = "net.sock.peer.port";
45+
46+
// HTTP https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/http-metrics/
47+
48+
public static final String HTTP_HTTP_SCHEME = "http.scheme";
49+
50+
public static final String HTTP_HTTP_FLAVOR = "http.flavor";
51+
52+
public static final String HTTP_NET_HOST_NAME = "net.host.name";
53+
54+
public static final String HTTP_NET_HOST_PORT = "net.host.port";
55+
56+
//TCP
57+
public static final String TCP_NET_HOST_NAME = "net.host.name";
58+
59+
public static final String TCP_NET_HOST_PORT = "net.host.port";
60+
61+
62+
public static final String CLIENT_PROTOCOL_TYPE = "client.protocol.type";
63+
64+
65+
}

Diff for: eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/Pair.java renamed to eventmesh-common/src/main/java/org/apache/eventmesh/common/Pair.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,32 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.runtime.common;
18+
package org.apache.eventmesh.common;
1919

20-
public class Pair<T1, T2> {
20+
public class Pair<Left, Right> {
2121

22-
private T1 object1;
23-
private T2 object2;
22+
private Left left;
2423

25-
public Pair(T1 object1, T2 object2) {
26-
this.object1 = object1;
27-
this.object2 = object2;
24+
private Right right;
25+
26+
public Pair(Left left, Right right) {
27+
this.left = left;
28+
this.right = right;
2829
}
2930

30-
public T1 getObject1() {
31-
return object1;
31+
public Left getLeft() {
32+
return left;
3233
}
3334

34-
public void setObject1(T1 object1) {
35-
this.object1 = object1;
35+
public void setLeft(Left left) {
36+
this.left = left;
3637
}
3738

38-
public T2 getObject2() {
39-
return object2;
39+
public Right getRight() {
40+
return right;
4041
}
4142

42-
public void setObject2(T2 object2) {
43-
this.object2 = object2;
43+
public void setRight(Right right) {
44+
this.right = right;
4445
}
4546
}
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.metrics.api.model;
18+
package org.apache.eventmesh.common.enums;
1919

20-
import lombok.AllArgsConstructor;
21-
import lombok.Data;
22-
23-
@Data
24-
@AllArgsConstructor
25-
public class RetrySummaryMetrics {
26-
27-
private long pendingRetryTimeouts;
20+
public enum ProtocolType {
21+
TCP,
22+
HTTP,
23+
GRPC
2824
}

Diff for: eventmesh-metrics-plugin/eventmesh-metrics-api/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
api project(":eventmesh-spi")
2020
implementation project(":eventmesh-common")
2121

22+
implementation 'io.opentelemetry:opentelemetry-api'
2223

2324
compileOnly 'org.projectlombok:lombok'
2425
annotationProcessor 'org.projectlombok:lombok'
@@ -27,4 +28,6 @@ dependencies {
2728
testAnnotationProcessor 'org.projectlombok:lombok'
2829

2930
testImplementation "org.mockito:mockito-core"
31+
testImplementation "org.mockito:mockito-inline"
3032
}
33+

Diff for: eventmesh-metrics-plugin/eventmesh-metrics-api/src/main/java/org/apache/eventmesh/metrics/api/MetricsRegistry.java

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import org.apache.eventmesh.spi.EventMeshExtensionType;
2222
import org.apache.eventmesh.spi.EventMeshSPI;
2323

24+
import org.apache.commons.collections4.CollectionUtils;
25+
26+
import java.util.Collection;
27+
2428
/**
2529
* The top-level interface of metrics registry, used to register different metrics. It should have multiple sub implementation, e.g. JVM, Prometheus,
2630
* i.g.
@@ -47,6 +51,17 @@ public interface MetricsRegistry {
4751
*/
4852
void register(Metric metric);
4953

54+
/**
55+
* Register Metrics, if the metric is already exist, it will do nothing.
56+
*
57+
* @param metrics
58+
*/
59+
default void register(Collection<Metric> metrics) {
60+
if (CollectionUtils.isNotEmpty(metrics)) {
61+
metrics.forEach(metric -> register(metric));
62+
}
63+
}
64+
5065
/**
5166
* Remove a metric, if the metric is not exist, it will do nothing.
5267
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.metrics.api.model;
19+
20+
public abstract class AbstractMetric implements Metric {
21+
22+
private InstrumentFurther further;
23+
24+
private String metricName;
25+
26+
public AbstractMetric(InstrumentFurther further, String metricName) {
27+
this.further = further;
28+
this.metricName = metricName;
29+
}
30+
31+
public AbstractMetric() {
32+
33+
}
34+
35+
@Override
36+
public void setInstrumentFurther(InstrumentFurther further) {
37+
this.further = further;
38+
}
39+
40+
@Override
41+
public InstrumentFurther getInstrumentFurther() {
42+
return this.further;
43+
}
44+
45+
@Override
46+
public String getName() {
47+
return metricName;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.metrics.api.model;
19+
20+
21+
import java.util.function.Supplier;
22+
23+
public abstract class AbstractObservableDoubleMetric extends AbstractObservableMetric<Double> {
24+
25+
private Supplier<Double> supplier;
26+
27+
public AbstractObservableDoubleMetric(InstrumentFurther further, String metricName) {
28+
super(further, metricName);
29+
}
30+
31+
public AbstractObservableDoubleMetric(InstrumentFurther further, String metricName, Supplier<Double> supplier) {
32+
super(further, metricName);
33+
this.supplier = supplier;
34+
}
35+
36+
public AbstractObservableDoubleMetric() {
37+
38+
}
39+
40+
public void supplier(Supplier<Double> supplier) {
41+
this.supplier = supplier;
42+
}
43+
44+
@Override
45+
public Supplier<Double> supplier() {
46+
return supplier;
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.metrics.api.model;
19+
20+
21+
import java.util.function.Supplier;
22+
23+
public abstract class AbstractObservableLongMetric extends AbstractObservableMetric<Long> {
24+
25+
private Supplier<Long> supplier;
26+
27+
public AbstractObservableLongMetric(InstrumentFurther further, String metricName) {
28+
super(further, metricName);
29+
}
30+
31+
public AbstractObservableLongMetric(InstrumentFurther further, String metricName, Supplier<Long> supplier) {
32+
super(further, metricName);
33+
this.supplier = supplier;
34+
}
35+
36+
public AbstractObservableLongMetric() {
37+
38+
}
39+
40+
public void supplier(Supplier<Long> supplier) {
41+
this.supplier = supplier;
42+
}
43+
44+
@Override
45+
public Supplier<Long> supplier() {
46+
return supplier;
47+
}
48+
}

0 commit comments

Comments
 (0)