-
Notifications
You must be signed in to change notification settings - Fork 642
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
[ISSUE #340]Integrate With OpenTelemetry for metrics in EventMesh #467
Changes from 15 commits
518c6fd
64e1331
69d4887
b1be2dd
4b82183
fad0381
90cfc5c
0cab2ce
091516f
0bc9d50
f5a79c2
16d9bca
02df827
a7b4c08
33cf1b7
da8e552
45a063d
d7b6ae2
0ce9316
5ca22bd
e29832b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.runtime.metrics.openTelemetry; | ||
|
||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.api.metrics.MeterProvider; | ||
import io.opentelemetry.api.metrics.common.Labels; | ||
import org.apache.eventmesh.runtime.metrics.http.SummaryMetrics; | ||
|
||
/** | ||
* test | ||
*/ | ||
public class OpenTelemetryExporter { | ||
OpenTelemetryExporterConfiguration configuration = new OpenTelemetryExporterConfiguration(); | ||
|
||
private SummaryMetrics summaryMetrics; | ||
|
||
private Meter meter; | ||
|
||
public OpenTelemetryExporter(SummaryMetrics summaryMetrics) { | ||
this.summaryMetrics = summaryMetrics; | ||
|
||
// it is important to initialize the OpenTelemetry SDK as early as possible in your process. | ||
MeterProvider meterProvider = configuration.initializeOpenTelemetry(); | ||
|
||
meter = meterProvider.get("OpenTelemetryExporter", "0.13.1"); | ||
} | ||
|
||
public void start(){ | ||
//maxHTTPTPS | ||
meter | ||
.doubleValueObserverBuilder("eventmesh.http.request.tps.elapsed.max") | ||
.setDescription("max TPS of HTTP") | ||
.setUnit("HTTP") | ||
.setUpdater(result -> result.observe(summaryMetrics.maxHTTPTPS(),Labels.empty())) | ||
.build(); | ||
|
||
//maxHTTPCost | ||
meter | ||
.longValueObserverBuilder("eventmesh.http.request.elapsed.max") | ||
.setDescription("max cost of HTTP") | ||
.setUnit("HTTP") | ||
.setUpdater(result -> result.observe(summaryMetrics.maxHTTPCost(), Labels.empty())) | ||
.build(); | ||
|
||
//avgHTTPCost | ||
meter | ||
.doubleValueObserverBuilder("eventmesh.http.request.elapsed.avg") | ||
.setDescription("avg cost of HTTP") | ||
.setUnit("HTTP") | ||
.setUpdater(result -> result.observe(summaryMetrics.avgHTTPCost(), Labels.empty())) | ||
.build(); | ||
} | ||
|
||
public void shutdown(){ | ||
configuration.shutdownPrometheusEndpoint(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.runtime.metrics.openTelemetry; | ||
|
||
import io.opentelemetry.api.metrics.MeterProvider; | ||
import io.opentelemetry.exporter.prometheus.PrometheusCollector; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.prometheus.client.exporter.HTTPServer; | ||
|
||
import java.io.IOException; | ||
|
||
//ues openTelemetry to export metrics data | ||
public class OpenTelemetryExporterConfiguration { | ||
|
||
private HTTPServer server;//Prometheus server | ||
|
||
int prometheusPort = 19090;//the endpoint to export metrics | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to add this to configuration properties. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about it, but I'm not very good at it. What language is involved? script? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most configuration is at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will have a try. |
||
|
||
/** | ||
* Initializes the Meter SDK and configures the prometheus collector with all default settings. | ||
* | ||
* | ||
* @return A MeterProvider for use in instrumentation. | ||
*/ | ||
public MeterProvider initializeOpenTelemetry() { | ||
SdkMeterProvider meterProvider = SdkMeterProvider.builder().buildAndRegisterGlobal(); | ||
|
||
PrometheusCollector.builder().setMetricProducer(meterProvider).buildAndRegister(); | ||
|
||
try { | ||
server = new HTTPServer(prometheusPort,true);//Use the daemon thread to start an HTTP server to serve the default Prometheus registry. | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return meterProvider; | ||
} | ||
|
||
public void shutdownPrometheusEndpoint() { | ||
server.stop(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Open Telemetry exporter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readme file should not exist in src There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I delete it,or put it in the design doc |
||
|
||
we can use Prometheus UI to see the metrics exported by openTelemetry | ||
|
||
# How to run Prometheus | ||
|
||
download Prometheus from https://prometheus.io/download/ | ||
remember to fix the [prometheus.yml](prometheus.yml) | ||
|
||
--- | ||
or use docker | ||
Start Prometheus instance with a configuration that sets up a HTTP collection job for ```127.0.0.1:19090``` | ||
|
||
See [prometheus.yml](prometheus.yml) | ||
|
||
```shell script | ||
docker run --network="host" --rm -it \ | ||
--name prometheus \ | ||
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \ | ||
prom/prometheus | ||
|
||
``` | ||
|
||
you can run the quickstart and open the Prometheus UI: | ||
http://localhost:9090/graph?g0.expr=max_HTTPCost&g0.tab=1&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h | ||
|
||
|
||
search the key word: | ||
|
||
*eventmesh_http_request_tps_elapsed_max* | ||
|
||
*eventmesh_http_request_elapsed_max* | ||
|
||
*eventmesh_http_request_elapsed_avg* | ||
|
||
## special explanation | ||
Prometheus runs on port 9090,Open telemetry exports data to port 19090,Prometheus will collect data from port 19090 | ||
|
||
the exporter is exporting the data in 'SummaryMetrics'(package org.apache.eventmesh.runtime.metrics.http;) | ||
|
||
The export mechanism I set is to export every 3 seconds, because QuickStart only has httpcost at a short time. If the interval is set too long, it will always be 0. In practical application, I think it should be set to more than 30 seconds |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yml file should not exist in src There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is ok. |
||
# 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. | ||
# | ||
global: | ||
scrape_interval: 15s | ||
scrape_timeout: 10s | ||
evaluation_interval: 15s | ||
alerting: | ||
alertmanagers: | ||
- static_configs: | ||
- targets: [] | ||
scheme: http | ||
timeout: 10s | ||
api_version: v1 | ||
scrape_configs: | ||
- job_name: prometheus | ||
honor_timestamps: true | ||
scrape_interval: 15s | ||
scrape_timeout: 10s | ||
metrics_path: /metrics | ||
scheme: http | ||
static_configs: | ||
- targets: | ||
- localhost:9090 | ||
- job_name: EventMesh_HTTP_export_test | ||
honor_timestamps: true | ||
scrape_interval: 15s | ||
scrape_timeout: 10s | ||
metrics_path: /metrics | ||
scheme: http | ||
static_configs: | ||
- targets: | ||
- 127.0.0.1:19090 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use other stable version? Using alpha does not seem to be a good choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok to use that. Otel's sdk metrics is in alpha although, it is widely used in https://github.com/open-telemetry/opentelemetry-java-instrumentation. This agent has been validated in enough prod environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK