-
Notifications
You must be signed in to change notification settings - Fork 3.3k
job execute collector #2265
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
base: master
Are you sure you want to change the base?
job execute collector #2265
Changes from all commits
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,8 @@ | ||
| package org.apache.shardingsphere.elasticjob.tracing.listener; | ||
|
|
||
| public class TracingType { | ||
| public static final String RDB = "RDB"; | ||
| public static final String METRICS = "METRICS"; | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.shardingsphere.elasticjob</groupId> | ||
| <artifactId>elasticjob-tracing</artifactId> | ||
| <version>3.1.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>elasticjob-tracing-observability</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>elasticjob-tracing-observability</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>3.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.shardingsphere.elasticjob</groupId> | ||
| <artifactId>elasticjob-tracing-api</artifactId> | ||
| <version>3.1.0-SNAPSHOT</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.micrometer</groupId> | ||
| <artifactId>micrometer-registry-prometheus</artifactId> | ||
| <version>1.11.3</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.apache.shardingsphere.elasticjob.tracing.metrics.binder; | ||
|
|
||
| import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| public class JobMetrics { | ||
| /** | ||
| * jobname -> state -> count | ||
| * support job level metrics | ||
| */ | ||
| private Map<String, Map<JobStatusTraceEvent.State, AtomicLong>> metrics = new ConcurrentHashMap<>(); | ||
|
|
||
| public void increase(String jobName, JobStatusTraceEvent.State state) { | ||
| metrics.computeIfAbsent(jobName, k -> new ConcurrentHashMap<>()); | ||
| metrics.get(jobName).computeIfAbsent(state, k -> new AtomicLong(0)).incrementAndGet(); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.apache.shardingsphere.elasticjob.tracing.metrics.config; | ||
|
|
||
| public class MetricConfig { | ||
| private Integer metricsPort = 9090; | ||
| private String metricsPath = "/metrics"; | ||
|
|
||
| public Integer getMetricsPort() { | ||
| return metricsPort; | ||
| } | ||
|
|
||
| public void setMetricsPort(Integer metricsPort) { | ||
| this.metricsPort = metricsPort; | ||
| } | ||
|
|
||
| public String getMetricsPath() { | ||
| return metricsPath; | ||
| } | ||
|
|
||
| public void setMetricsPath(String metricsPath) { | ||
| this.metricsPath = metricsPath; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.apache.shardingsphere.elasticjob.tracing.metrics.config; | ||
|
|
||
| public class MetricsTracingStorageConfiguration { | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||
| /* | ||||||
| * 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.shardingsphere.elasticjob.tracing.metrics.listener; | ||||||
|
|
||||||
| import com.sun.net.httpserver.HttpServer; | ||||||
| import io.micrometer.core.instrument.composite.CompositeMeterRegistry; | ||||||
| import io.micrometer.prometheus.PrometheusConfig; | ||||||
| import io.micrometer.prometheus.PrometheusMeterRegistry; | ||||||
| import org.apache.commons.lang3.StringUtils; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.event.JobExecutionEvent; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.listener.TracingListener; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.metrics.binder.JobMetrics; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.metrics.config.MetricConfig; | ||||||
| import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
| import java.io.OutputStream; | ||||||
| import java.net.InetSocketAddress; | ||||||
|
|
||||||
|
|
||||||
| public class JobMetricsListener implements TracingListener { | ||||||
| private static final Logger logger = LoggerFactory.getLogger(JobMetricsListener.class); | ||||||
|
|
||||||
| private JobMetrics jobMetrics; | ||||||
|
|
||||||
| CompositeMeterRegistry composite = new CompositeMeterRegistry(); | ||||||
|
|
||||||
|
|
||||||
| public JobMetricsListener(MetricConfig metricConfig) { | ||||||
| //open jvm http port to export metrics | ||||||
| jobMetrics = new JobMetrics(); | ||||||
|
|
||||||
|
|
||||||
| //开启一个服务,用于暴露指标 | ||||||
|
||||||
| //开启一个服务,用于暴露指标 | |
| // Start a service to expose metrics |
Copilot
AI
Sep 6, 2025
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.
The port 8081 is hardcoded, but the MetricConfig class has a metricsPort field. This should use metricConfig.getMetricsPort() instead of the hardcoded value.
| server = HttpServer.create(new InetSocketAddress(8081), 0); | |
| server = HttpServer.create(new InetSocketAddress(metricConfig.getMetricsPort()), 0); |
Copilot
AI
Sep 6, 2025
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.
The metrics path '/metrics' is hardcoded, but the MetricConfig class has a metricsPath field. This should use metricConfig.getMetricsPath() instead of the hardcoded value.
| server.createContext("/metrics", httpExchange -> { | |
| server.createContext(metricConfig.getMetricsPath(), httpExchange -> { |
Copilot
AI
Sep 6, 2025
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.
Chinese comment should be replaced with English: '// Start the service'.
| //开启服务 | |
| // Start the service |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||
| /* | ||||||
| * 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.shardingsphere.elasticjob.tracing.metrics.listener; | ||||||
|
|
||||||
| import org.apache.shardingsphere.elasticjob.tracing.exception.TracingConfigurationException; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.listener.TracingListener; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.listener.TracingListenerConfiguration; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.listener.TracingType; | ||||||
| import org.apache.shardingsphere.elasticjob.tracing.metrics.config.MetricConfig; | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * RDB tracing listener configuration. | ||||||
|
||||||
| * RDB tracing listener configuration. | |
| * Metrics tracing listener configuration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package org.apache.shardingsphere.elasticjob.tracing.metrics; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| org.apache.shardingsphere.elasticjob.tracing.metrics.listener.JobMetricsTracingListenerConfiguration |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||
| package org.apache.shardingsphere.elasticjob; | ||||||
|
|
||||||
| import junit.framework.Test; | ||||||
| import junit.framework.TestCase; | ||||||
| import junit.framework.TestSuite; | ||||||
|
|
||||||
| /** | ||||||
| * Unit test for simple App. | ||||||
| */ | ||||||
| public class AppTest | ||||||
| extends TestCase | ||||||
| { | ||||||
| /** | ||||||
| * Create the test case | ||||||
| * | ||||||
| * @param testName name of the test case | ||||||
| */ | ||||||
| public AppTest( String testName ) | ||||||
| { | ||||||
| super( testName ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @return the suite of tests being tested | ||||||
| */ | ||||||
| public static Test suite() | ||||||
| { | ||||||
| return new TestSuite( AppTest.class ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Rigourous Test :-) | ||||||
|
||||||
| * Rigourous Test :-) | |
| * Rigorous Test :-) |
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.
JUnit version 3.8.1 is extremely outdated. Consider updating to a modern version like JUnit 5 or at least JUnit 4.13.2 for better testing capabilities and security updates.