Skip to content

Commit

Permalink
[ISSUE apache#3430] Refactor eventmesh-metrics-prometheus module (apa…
Browse files Browse the repository at this point in the history
…che#4840)

* [ISSUE apache#3430]Refactor eventmesh-metrics-prometheus module

* optimize code

* optimize code
  • Loading branch information
mxsm committed Apr 19, 2024
1 parent 1fdb5b2 commit a899e54
Show file tree
Hide file tree
Showing 100 changed files with 4,610 additions and 1,839 deletions.
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,13 @@ subprojects {
dependency "io.dropwizard.metrics:metrics-annotation:4.1.0"
dependency "io.dropwizard.metrics:metrics-json:4.1.0"

dependency 'io.opentelemetry:opentelemetry-api:1.3.0'
dependency 'io.opentelemetry:opentelemetry-sdk:1.3.0'
dependency 'io.opentelemetry:opentelemetry-sdk-metrics:1.3.0-alpha'
dependency 'io.opentelemetry:opentelemetry-exporter-prometheus:1.3.0-alpha'
dependency 'io.prometheus:simpleclient:0.8.1'
dependency 'io.prometheus:simpleclient_httpserver:0.8.1'
dependency 'io.opentelemetry:opentelemetry-exporter-zipkin:1.3.0'
dependency 'io.opentelemetry:opentelemetry-semconv:1.3.0-alpha'
dependency 'io.opentelemetry:opentelemetry-exporter-jaeger:1.4.0'
dependency 'io.opentelemetry:opentelemetry-api:1.36.0'
dependency 'io.opentelemetry:opentelemetry-sdk:1.36.0'
dependency 'io.opentelemetry:opentelemetry-sdk-metrics:1.36.0'
dependency 'io.opentelemetry:opentelemetry-exporter-prometheus:1.36.0-alpha'
dependency 'io.opentelemetry:opentelemetry-exporter-zipkin:1.36.0'
dependency 'io.opentelemetry:opentelemetry-semconv:1.30.1-alpha'
dependency 'io.opentelemetry:opentelemetry-exporter-jaeger:1.34.1'

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

package org.apache.eventmesh.common;


public class MetricsConstants {

private MetricsConstants() {

}

public static final String UNKOWN = "unkown";

public static final String LABEL_PROCESSOR = "processor";

public static final String CLIENT_ADDRESS = "client.address";

public static final String RPC_SYSTEM = "rpc.system";

public static final String RPC_SERVICE = "rpc.service";

//GRPC-https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/rpc-metrics/
public static final String GRPC_NET_PEER_PORT = "net.peer.port";

public static final String GRPC_NET_PEER_NAME = "net.peer.name";

public static final String GRPC_NET_SOCK_PEER_ADDR = "net.sock.peer.addr";

public static final String GRPC_NET_SOCK_PEER_PORT = "net.sock.peer.port";

// HTTP https://opentelemetry.io/docs/reference/specification/metrics/semantic_conventions/http-metrics/

public static final String HTTP_HTTP_SCHEME = "http.scheme";

public static final String HTTP_HTTP_FLAVOR = "http.flavor";

public static final String HTTP_NET_HOST_NAME = "net.host.name";

public static final String HTTP_NET_HOST_PORT = "net.host.port";

//TCP
public static final String TCP_NET_HOST_NAME = "net.host.name";

public static final String TCP_NET_HOST_PORT = "net.host.port";


public static final String CLIENT_PROTOCOL_TYPE = "client.protocol.type";


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
* limitations under the License.
*/

package org.apache.eventmesh.runtime.common;
package org.apache.eventmesh.common;

public class Pair<T1, T2> {
public class Pair<Left, Right> {

private T1 object1;
private T2 object2;
private Left left;

public Pair(T1 object1, T2 object2) {
this.object1 = object1;
this.object2 = object2;
private Right right;

public Pair(Left left, Right right) {
this.left = left;
this.right = right;
}

public T1 getObject1() {
return object1;
public Left getLeft() {
return left;
}

public void setObject1(T1 object1) {
this.object1 = object1;
public void setLeft(Left left) {
this.left = left;
}

public T2 getObject2() {
return object2;
public Right getRight() {
return right;
}

public void setObject2(T2 object2) {
this.object2 = object2;
public void setRight(Right right) {
this.right = right;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
* limitations under the License.
*/

package org.apache.eventmesh.metrics.api.model;
package org.apache.eventmesh.common.enums;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class RetrySummaryMetrics {

private long pendingRetryTimeouts;
public enum ProtocolType {
TCP,
HTTP,
GRPC
}
3 changes: 3 additions & 0 deletions eventmesh-metrics-plugin/eventmesh-metrics-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
api project(":eventmesh-spi")
implementation project(":eventmesh-common")

implementation 'io.opentelemetry:opentelemetry-api'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -27,4 +28,6 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok'

testImplementation "org.mockito:mockito-core"
testImplementation "org.mockito:mockito-inline"
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import org.apache.eventmesh.spi.EventMeshExtensionType;
import org.apache.eventmesh.spi.EventMeshSPI;

import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;

/**
* The top-level interface of metrics registry, used to register different metrics. It should have multiple sub implementation, e.g. JVM, Prometheus,
* i.g.
Expand All @@ -47,6 +51,17 @@ public interface MetricsRegistry {
*/
void register(Metric metric);

/**
* Register Metrics, if the metric is already exist, it will do nothing.
*
* @param metrics
*/
default void register(Collection<Metric> metrics) {
if (CollectionUtils.isNotEmpty(metrics)) {
metrics.forEach(metric -> register(metric));
}
}

/**
* Remove a metric, if the metric is not exist, it will do nothing.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.
*/

package org.apache.eventmesh.metrics.api.model;

public abstract class AbstractMetric implements Metric {

private InstrumentFurther further;

private String metricName;

public AbstractMetric(InstrumentFurther further, String metricName) {
this.further = further;
this.metricName = metricName;
}

public AbstractMetric() {

}

@Override
public void setInstrumentFurther(InstrumentFurther further) {
this.further = further;
}

@Override
public InstrumentFurther getInstrumentFurther() {
return this.further;
}

@Override
public String getName() {
return metricName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.
*/

package org.apache.eventmesh.metrics.api.model;


import java.util.function.Supplier;

public abstract class AbstractObservableDoubleMetric extends AbstractObservableMetric<Double> {

private Supplier<Double> supplier;

public AbstractObservableDoubleMetric(InstrumentFurther further, String metricName) {
super(further, metricName);
}

public AbstractObservableDoubleMetric(InstrumentFurther further, String metricName, Supplier<Double> supplier) {
super(further, metricName);
this.supplier = supplier;
}

public AbstractObservableDoubleMetric() {

}

public void supplier(Supplier<Double> supplier) {
this.supplier = supplier;
}

@Override
public Supplier<Double> supplier() {
return supplier;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.
*/

package org.apache.eventmesh.metrics.api.model;


import java.util.function.Supplier;

public abstract class AbstractObservableLongMetric extends AbstractObservableMetric<Long> {

private Supplier<Long> supplier;

public AbstractObservableLongMetric(InstrumentFurther further, String metricName) {
super(further, metricName);
}

public AbstractObservableLongMetric(InstrumentFurther further, String metricName, Supplier<Long> supplier) {
super(further, metricName);
this.supplier = supplier;
}

public AbstractObservableLongMetric() {

}

public void supplier(Supplier<Long> supplier) {
this.supplier = supplier;
}

@Override
public Supplier<Long> supplier() {
return supplier;
}
}
Loading

0 comments on commit a899e54

Please sign in to comment.