diff --git a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
index 6a879be4f1..0f04904a87 100644
--- a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
+++ b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
@@ -69,6 +69,9 @@ private ElasticJobExecutor(final ElasticJob elasticJob, final JobConfiguration j
executorContext = new ExecutorContext(jobFacade.loadJobConfiguration(true));
itemErrorMessages = new ConcurrentHashMap<>(jobConfig.getShardingTotalCount(), 1);
}
+ public void init(String jobName){
+ jobFacade.postJobStatusTraceEvent("0", State.TASK_INIT, String.format("Job '%s' init success.", jobName));
+ }
/**
* Execute job.
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/event/JobStatusTraceEvent.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/event/JobStatusTraceEvent.java
index 9a1b679e66..bc17c66008 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/event/JobStatusTraceEvent.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/event/JobStatusTraceEvent.java
@@ -57,7 +57,7 @@ public final class JobStatusTraceEvent implements JobEvent {
private Date creationTime = new Date();
public enum State {
- TASK_STAGING, TASK_RUNNING, TASK_FINISHED, TASK_KILLED, TASK_LOST, TASK_FAILED, TASK_ERROR, TASK_DROPPED, TASK_GONE, TASK_GONE_BY_OPERATOR, TASK_UNREACHABLE, TASK_UNKNOWN
+ TASK_INIT, TASK_STAGING, TASK_RUNNING, TASK_FINISHED, TASK_KILLED, TASK_LOST, TASK_FAILED, TASK_ERROR, TASK_DROPPED, TASK_GONE, TASK_GONE_BY_OPERATOR, TASK_UNREACHABLE, TASK_UNKNOWN
}
public enum Source {
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingType.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingType.java
new file mode 100644
index 0000000000..b8ae0becef
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingType.java
@@ -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";
+
+
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/pom.xml b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/pom.xml
new file mode 100644
index 0000000000..f492129d61
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/pom.xml
@@ -0,0 +1,39 @@
+
+ 4.0.0
+
+ org.apache.shardingsphere.elasticjob
+ elasticjob-tracing
+ 3.1.0-SNAPSHOT
+
+
+ elasticjob-tracing-observability
+ jar
+
+ elasticjob-tracing-observability
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ org.apache.shardingsphere.elasticjob
+ elasticjob-tracing-api
+ 3.1.0-SNAPSHOT
+ compile
+
+
+ io.micrometer
+ micrometer-registry-prometheus
+ 1.11.3
+
+
+
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/binder/JobMetrics.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/binder/JobMetrics.java
new file mode 100644
index 0000000000..e6ead5e0d6
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/binder/JobMetrics.java
@@ -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> 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();
+ }
+
+
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricConfig.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricConfig.java
new file mode 100644
index 0000000000..9396f1d5b9
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricConfig.java
@@ -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;
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricsTracingStorageConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricsTracingStorageConfiguration.java
new file mode 100644
index 0000000000..1ee3ed1613
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/config/MetricsTracingStorageConfiguration.java
@@ -0,0 +1,4 @@
+package org.apache.shardingsphere.elasticjob.tracing.metrics.config;
+
+public class MetricsTracingStorageConfiguration {
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsListener.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsListener.java
new file mode 100644
index 0000000000..8eb03dd3db
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsListener.java
@@ -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();
+
+
+ //开启一个服务,用于暴露指标
+ HttpServer server = null;
+ try {
+ PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
+ composite.add(prometheusRegistry);
+
+ server = HttpServer.create(new InetSocketAddress(8081), 0);
+
+ server.createContext("/metrics", httpExchange -> {
+ String response = prometheusRegistry.scrape();
+ httpExchange.sendResponseHeaders(200, response.getBytes().length);
+ try (OutputStream os = httpExchange.getResponseBody()) {
+ os.write(response.getBytes());
+ }
+ });
+ //开启服务
+ new Thread(server::start).start();
+ } catch (IOException e) {
+ logger.error("metrics start error:{}", e.getMessage(), e);
+ }
+ HttpServer finalServer = server;
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ if (finalServer != null) {
+ finalServer.stop(3000);
+ }
+ }));
+
+ }
+
+ @Override
+ public void listen(JobExecutionEvent jobExecutionEvent) {
+
+ }
+
+ @Override
+ public void listen(JobStatusTraceEvent jobStatusTraceEvent) {
+ if (jobStatusTraceEvent == null || StringUtils.isBlank(jobStatusTraceEvent.getJobName())) {
+ return;
+ }
+ jobMetrics.increase(jobStatusTraceEvent.getJobName(), jobStatusTraceEvent.getState());
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsTracingListenerConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsTracingListenerConfiguration.java
new file mode 100644
index 0000000000..a0d0345fb2
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/listener/JobMetricsTracingListenerConfiguration.java
@@ -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.
+ */
+public final class JobMetricsTracingListenerConfiguration implements TracingListenerConfiguration {
+
+ @Override
+ public TracingListener createTracingListener(final MetricConfig metricConfig) throws TracingConfigurationException {
+ return new JobMetricsListener(metricConfig);
+ }
+
+ @Override
+ public String getType() {
+ return TracingType.METRICS;
+ }
+
+
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/package-info.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/package-info.java
new file mode 100644
index 0000000000..bd2fa093cd
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/java/org/apache/shardingsphere/elasticjob/tracing/metrics/package-info.java
@@ -0,0 +1 @@
+package org.apache.shardingsphere.elasticjob.tracing.metrics;
\ No newline at end of file
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.listener.TracingListenerConfiguration b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.listener.TracingListenerConfiguration
new file mode 100644
index 0000000000..5e998d3d5c
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.listener.TracingListenerConfiguration
@@ -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
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/test/java/org/apache/shardingsphere/elasticjob/AppTest.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/test/java/org/apache/shardingsphere/elasticjob/AppTest.java
new file mode 100644
index 0000000000..ae433e544d
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-observability/src/test/java/org/apache/shardingsphere/elasticjob/AppTest.java
@@ -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 :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java
index f6747e5235..e05f68d61c 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java
@@ -20,6 +20,7 @@
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 javax.sql.DataSource;
import java.sql.SQLException;
@@ -40,6 +41,6 @@ public TracingListener createTracingListener(final DataSource storage) throws Tr
@Override
public String getType() {
- return "RDB";
+ return TracingType.RDB;
}
}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/pom.xml b/elasticjob-ecosystem/elasticjob-tracing/pom.xml
index cb3660a4e5..bce2bca944 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/pom.xml
+++ b/elasticjob-ecosystem/elasticjob-tracing/pom.xml
@@ -30,5 +30,6 @@
elasticjob-tracing-api
elasticjob-tracing-rdb
+ elasticjob-tracing-observability
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
index ffee2d7d87..0ffa9b3d7a 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
@@ -52,30 +52,30 @@
* Job scheduler.
*/
public final class JobScheduler {
-
+
static {
ElasticJobServiceLoader.registerTypedService(JobErrorHandlerPropertiesValidator.class);
}
-
+
private static final String JOB_EXECUTOR_DATA_MAP_KEY = "jobExecutor";
-
+
@Getter
private final CoordinatorRegistryCenter regCenter;
-
+
@Getter
private final JobConfiguration jobConfig;
-
+
private final SetUpFacade setUpFacade;
-
+
private final SchedulerFacade schedulerFacade;
-
+
private final LiteJobFacade jobFacade;
-
+
private final ElasticJobExecutor jobExecutor;
-
+
@Getter
private final JobScheduleController jobScheduleController;
-
+
public JobScheduler(final CoordinatorRegistryCenter regCenter, final ElasticJob elasticJob, final JobConfiguration jobConfig) {
Preconditions.checkArgument(null != elasticJob, "Elastic job cannot be null.");
this.regCenter = regCenter;
@@ -115,22 +115,22 @@ private Collection getElasticJobListeners(final JobConfigura
.map(type -> ElasticJobListenerFactory.createListener(type).orElseThrow(() -> new IllegalArgumentException(String.format("Can not find job listener type '%s'.", type))))
.collect(Collectors.toList());
}
-
+
private Optional> findTracingConfiguration() {
return jobConfig.getExtraConfigurations().stream().filter(each -> each instanceof TracingConfiguration).findFirst().map(extraConfig -> (TracingConfiguration>) extraConfig);
}
-
+
private void validateJobProperties() {
validateJobErrorHandlerProperties();
}
-
+
private void validateJobErrorHandlerProperties() {
if (null != jobConfig.getJobErrorHandlerType()) {
ElasticJobServiceLoader.newTypedServiceInstance(JobErrorHandlerPropertiesValidator.class, jobConfig.getJobErrorHandlerType(), jobConfig.getProps())
.ifPresent(validator -> validator.validate(jobConfig.getProps()));
}
}
-
+
private void setGuaranteeServiceForElasticJobListeners(final CoordinatorRegistryCenter regCenter, final Collection elasticJobListeners) {
GuaranteeService guaranteeService = new GuaranteeService(regCenter, jobConfig.getJobName());
for (ElasticJobListener each : elasticJobListeners) {
@@ -139,14 +139,14 @@ private void setGuaranteeServiceForElasticJobListeners(final CoordinatorRegistry
}
}
}
-
+
private JobScheduleController createJobScheduleController() {
JobScheduleController result = new JobScheduleController(createScheduler(), createJobDetail(), getJobConfig().getJobName());
JobRegistry.getInstance().registerJob(getJobConfig().getJobName(), result);
registerStartUpInfo();
return result;
}
-
+
private Scheduler createScheduler() {
Scheduler result;
try {
@@ -159,7 +159,7 @@ private Scheduler createScheduler() {
}
return result;
}
-
+
private Properties getQuartzProps() {
Properties result = new Properties();
result.put("org.quartz.threadPool.class", SimpleThreadPool.class.getName());
@@ -170,20 +170,21 @@ private Properties getQuartzProps() {
result.put("org.quartz.plugin.shutdownhook.cleanShutdown", Boolean.TRUE.toString());
return result;
}
-
+
private JobDetail createJobDetail() {
JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(getJobConfig().getJobName()).build();
result.getJobDataMap().put(JOB_EXECUTOR_DATA_MAP_KEY, jobExecutor);
return result;
}
-
+
private void registerStartUpInfo() {
JobRegistry.getInstance().registerRegistryCenter(jobConfig.getJobName(), regCenter);
JobRegistry.getInstance().addJobInstance(jobConfig.getJobName(), new JobInstance());
JobRegistry.getInstance().setCurrentShardingTotalCount(jobConfig.getJobName(), jobConfig.getShardingTotalCount());
setUpFacade.registerStartUpInfo(!jobConfig.isDisabled());
+ jobExecutor.init(jobConfig.getJobName());
}
-
+
/**
* Shutdown job.
*/
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
index f84984c182..526d767170 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
@@ -83,5 +83,11 @@
com.h2database
h2
+
+ org.apache.shardingsphere.elasticjob
+ elasticjob-tracing-observability
+ 3.1.0-SNAPSHOT
+ compile
+
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/tracing/ElasticJobTracingConfiguration.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/tracing/ElasticJobTracingConfiguration.java
index 3dd0afe586..d5da22b1c6 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/tracing/ElasticJobTracingConfiguration.java
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/tracing/ElasticJobTracingConfiguration.java
@@ -19,6 +19,8 @@
import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.listener.TracingType;
+import org.apache.shardingsphere.elasticjob.tracing.metrics.config.MetricConfig;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -29,6 +31,8 @@
import javax.sql.DataSource;
+import static org.apache.shardingsphere.elasticjob.tracing.listener.TracingType.*;
+
/**
* ElasticJob tracing auto configuration.
*/
@@ -56,18 +60,35 @@ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
/**
* Create a bean of tracing configuration.
*
- * @param dataSource required by constructor
+ * @param dataSource required by constructor
* @param tracingDataSource tracing ataSource
* @return a bean of tracing configuration
*/
@Bean
@ConditionalOnBean(DataSource.class)
- @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = "RDB")
+ @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = RDB)
public TracingConfiguration tracingConfiguration(final DataSource dataSource, @Nullable final DataSource tracingDataSource) {
DataSource ds = tracingDataSource;
if (ds == null) {
ds = dataSource;
}
- return new TracingConfiguration<>("RDB", ds);
+ return new TracingConfiguration<>(RDB, ds);
+ }
+
+ /**
+ * Create a bean of tracing configuration.
+ *
+ * @param dataSource required by constructor
+ * @param tracingDataSource tracing ataSource
+ * @return a bean of tracing configuration
+ */
+ @Bean
+ @ConditionalOnBean(MetricConfig.class)
+ @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = TracingType.METRICS)
+ public TracingConfiguration tracingConfigurationMetrics(MetricConfig metricConfig) {
+ if (metricConfig == null) {
+ metricConfig = new MetricConfig();
+ }
+ return new TracingConfiguration<>(TracingType.METRICS, metricConfig);
}
}