Skip to content

Commit 44e2c21

Browse files
Consolidate Metrics Query and Metrics Proccessor Services2
1 parent f27bed3 commit 44e2c21

File tree

16 files changed

+28
-167
lines changed

16 files changed

+28
-167
lines changed

Diff for: cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/AppFabricServiceRuntimeModule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ protected void configure() {
314314
servicesNamesBinder.addBinding().toInstance(Constants.Service.APP_FABRIC_HTTP);
315315

316316
// for PingHandler
317-
servicesNamesBinder.addBinding().toInstance(Constants.Service.METRICS_PROCESSOR);
317+
servicesNamesBinder.addBinding().toInstance(Constants.Service.METRICS);
318318
servicesNamesBinder.addBinding().toInstance(Constants.Service.LOGSAVER);
319319
servicesNamesBinder.addBinding().toInstance(Constants.Service.TRANSACTION_HTTP);
320320
servicesNamesBinder.addBinding().toInstance(Constants.Service.RUNTIME);
@@ -325,7 +325,7 @@ protected void configure() {
325325
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.APP_FABRIC_HTTP);
326326

327327
// for PingHandler
328-
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.METRICS_PROCESSOR);
328+
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.METRICS);
329329
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.LOGSAVER);
330330
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.TRANSACTION_HTTP);
331331
handlerHookNamesBinder.addBinding().toInstance(Constants.Service.RUNTIME);

Diff for: cdap-common/src/main/java/io/cdap/cdap/common/conf/Constants.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static final class Service {
129129
public static final String LOG_QUERY = "log.query";
130130
public static final String GATEWAY = "gateway";
131131
public static final String MASTER_SERVICES = "master.services";
132-
public static final String METRICS_PROCESSOR = "metrics";
132+
public static final String METRICS_PROCESSOR = "metrics.processor";
133133
public static final String DATASET_MANAGER = "dataset.service";
134134
public static final String DATASET_EXECUTOR = "dataset.executor";
135135
public static final String EXTERNAL_AUTHENTICATION = "external.authentication";
@@ -969,7 +969,7 @@ public static final class Metrics {
969969
ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE,
970970
NamespaceId.SYSTEM.getNamespace(),
971971
Constants.Metrics.Tag.COMPONENT,
972-
Constants.Service.METRICS_PROCESSOR);
972+
Constants.Service.METRICS);
973973

974974
public static final Map<String, String> TRANSACTION_MANAGER_CONTEXT =
975975
ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE,

Diff for: cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/RouterPathLookup.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private enum AllowedMethod {
5353
Constants.Service.LOG_QUERY);
5454
public static final RouteDestination LOG_SAVER = new RouteDestination(Constants.Service.LOGSAVER);
5555
public static final RouteDestination METRICS_PROCESSOR = new RouteDestination(
56-
Constants.Service.METRICS_PROCESSOR);
56+
Constants.Service.METRICS);
5757
public static final RouteDestination DATASET_EXECUTOR = new RouteDestination(
5858
Constants.Service.DATASET_EXECUTOR);
5959
public static final RouteDestination MESSAGING = new RouteDestination(

Diff for: cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RouterPathLookupTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public void testSystemServiceStatusPaths() {
370370
RouterPathLookup.LOG_SAVER);
371371
assertRouting(String.format("/v3/system/services/%s/status", Constants.Service.TRANSACTION),
372372
RouterPathLookup.TRANSACTION);
373-
assertRouting(String.format("/v3/system/services/%s/status", Constants.Service.METRICS_PROCESSOR),
373+
assertRouting(String.format("/v3/system/services/%s/status", Constants.Service.METRICS),
374374
RouterPathLookup.METRICS_PROCESSOR);
375375
assertRouting(String.format("/v3/system/services/%s/status", Constants.Service.METRICS),
376376
RouterPathLookup.METRICS);
@@ -393,7 +393,7 @@ public void testSystemServiceStacksPaths() {
393393
RouterPathLookup.LOG_SAVER);
394394
assertRouting(String.format("/v3/system/services/%s/stacks", Constants.Service.TRANSACTION),
395395
RouterPathLookup.TRANSACTION);
396-
assertRouting(String.format("/v3/system/services/%s/stacks", Constants.Service.METRICS_PROCESSOR),
396+
assertRouting(String.format("/v3/system/services/%s/stacks", Constants.Service.METRICS),
397397
RouterPathLookup.METRICS_PROCESSOR);
398398
assertRouting(String.format("/v3/system/services/%s/stacks", Constants.Service.METRICS),
399399
RouterPathLookup.METRICS);

Diff for: cdap-master/src/main/java/io/cdap/cdap/common/MasterUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static Set<ServiceResourceKeys> createSystemServicesResourceKeysSet(CConf
5454
Constants.Metrics.NUM_INSTANCES,
5555
Constants.Metrics.MAX_INSTANCES))
5656
.add(new ServiceResourceKeys(cConf,
57-
Constants.Service.METRICS_PROCESSOR,
57+
Constants.Service.METRICS,
5858
Constants.MetricsProcessor.MEMORY_MB,
5959
Constants.MetricsProcessor.NUM_CORES,
6060
Constants.MetricsProcessor.NUM_INSTANCES,

Diff for: cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MasterTwillApplication.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.collect.ImmutableMap;
2222
import io.cdap.cdap.common.conf.CConfiguration;
2323
import io.cdap.cdap.common.conf.Constants;
24+
import io.cdap.cdap.common.conf.Constants.Service;
2425
import io.cdap.cdap.common.lang.jar.BundleJarUtil;
2526
import io.cdap.cdap.common.twill.AbortOnTimeoutEventHandler;
2627
import io.cdap.cdap.common.utils.DirUtils;
@@ -65,7 +66,7 @@ public class MasterTwillApplication implements TwillApplication {
6566
.put(Constants.Service.TRANSACTION, "data.tx.")
6667
.put(Constants.Service.DATASET_EXECUTOR, "dataset.executor.")
6768
.put(Constants.Service.LOGSAVER, "log.saver.")
68-
.put(Constants.Service.METRICS_PROCESSOR, "metrics.processor.")
69+
.put(Service.METRICS_PROCESSOR, "metrics.")
6970
.put(Constants.Service.METRICS, "metrics.")
7071
.build();
7172

@@ -165,9 +166,9 @@ private Builder.RunnableSetter addMetricsProcessor(Builder.MoreRunnable builder)
165166
ResourceSpecification resourceSpec = createResourceSpecification(
166167
Constants.MetricsProcessor.NUM_CORES,
167168
Constants.MetricsProcessor.MEMORY_MB,
168-
Constants.Service.METRICS_PROCESSOR);
169-
return addResources(Constants.Service.METRICS_PROCESSOR,
170-
builder.add(new MetricsProcessorTwillRunnable(Constants.Service.METRICS_PROCESSOR,
169+
Constants.Service.METRICS);
170+
return addResources(Constants.Service.METRICS,
171+
builder.add(new MetricsProcessorTwillRunnable(Constants.Service.METRICS,
171172
CCONF_NAME, HCONF_NAME), resourceSpec));
172173
}
173174

Diff for: cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MetricsProcessorTwillRunnable.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ public MetricsProcessorTwillRunnable(String name, String cConfName, String hConf
8181

8282
@Override
8383
protected Injector doInit(TwillContext context) {
84-
getCConfiguration().set(Constants.MetricsProcessor.BIND_ADDRESS,
84+
getCConfiguration().set(Constants.Metrics.ADDRESS,
8585
context.getHost().getCanonicalHostName());
8686
// Set the hostname of the machine so that cConf can be used to start internal services
8787
LOG.info("{} Setting host name to {}", name, context.getHost().getCanonicalHostName());
8888

8989
instanceId = context.getInstanceId();
9090

91-
String txClientId = String.format("cdap.service.%s.%d", Constants.Service.METRICS_PROCESSOR,
91+
String txClientId = String.format("cdap.service.%s.%d", Constants.Service.METRICS,
9292
context.getInstanceId());
9393
injector = createGuiceInjector(getCConfiguration(), getConfiguration(), txClientId, context);
9494

9595
injector.getInstance(LogAppenderInitializer.class).initialize();
9696
LoggingContextAccessor.setLoggingContext(
9797
new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(),
9898
Constants.Logging.COMPONENT_NAME,
99-
Constants.Service.METRICS_PROCESSOR));
99+
Constants.Service.METRICS));
100100
return injector;
101101
}
102102

Diff for: cdap-master/src/main/java/io/cdap/cdap/master/environment/k8s/MetricsServiceMain.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import com.google.inject.Injector;
2222
import com.google.inject.Key;
2323
import com.google.inject.Module;
24-
import com.google.inject.PrivateModule;
25-
import com.google.inject.Scopes;
2624
import com.google.inject.assistedinject.FactoryModuleBuilder;
2725
import io.cdap.cdap.api.metrics.MetricsCollectionService;
2826
import io.cdap.cdap.api.metrics.MetricsContext;
@@ -42,7 +40,7 @@
4240
import io.cdap.cdap.metrics.process.MessagingMetricsProcessorServiceFactory;
4341
import io.cdap.cdap.metrics.process.MetricsAdminSubscriberService;
4442
import io.cdap.cdap.metrics.process.loader.MetricsWriterModule;
45-
import io.cdap.cdap.metrics.service.MetricsService;
43+
import io.cdap.cdap.metrics.query.MetricsQueryService;
4644
import io.cdap.cdap.metrics.store.MetricsCleanUpService;
4745
import io.cdap.cdap.proto.id.NamespaceId;
4846
import io.cdap.cdap.security.authorization.AuthorizationEnforcementModule;
@@ -79,14 +77,7 @@ protected List<Module> getServiceModules(MasterEnvironment masterEnv,
7977
new MetricsProcessorStatusServiceModule(),
8078
new MetricsHandlerModule(),
8179
new DFSLocationModule(),
82-
new MetricsWriterModule(),
83-
new PrivateModule() {
84-
@Override
85-
protected void configure() {
86-
bind(MetricsService.class).in(Scopes.SINGLETON);
87-
expose(MetricsService.class);
88-
}
89-
}
80+
new MetricsWriterModule()
9081
);
9182
}
9283

@@ -106,7 +97,7 @@ protected void addServices(Injector injector, List<? super Service> services,
10697

10798
services.add(injector.getInstance(MessagingMetricsProcessorServiceFactory.class)
10899
.create(topicNumbers, metricsContext, 0));
109-
services.add(injector.getInstance(MetricsService.class));
100+
services.add(injector.getInstance(MetricsQueryService.class));
110101
services.add(injector.getInstance(MetricsAdminSubscriberService.class));
111102
services.add(injector.getInstance(MetricsCleanUpService.class));
112103
Binding<ZKClientService> zkBinding = injector.getExistingBinding(

Diff for: cdap-standalone/src/main/java/io/cdap/cdap/StandaloneMain.java

-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ private static List<Module> createPersistentModules(CConfiguration cConf, Config
525525
cConf.set(Constants.Transaction.Container.ADDRESS, localhost);
526526
cConf.set(Constants.Dataset.Executor.ADDRESS, localhost);
527527
cConf.set(Constants.Metrics.ADDRESS, localhost);
528-
cConf.set(Constants.MetricsProcessor.BIND_ADDRESS, localhost);
529528
cConf.set(Constants.LogSaver.ADDRESS, localhost);
530529
cConf.set(Constants.LogQuery.ADDRESS, localhost);
531530
cConf.set(Constants.Metadata.SERVICE_BIND_ADDRESS, localhost);

Diff for: cdap-unit-test/src/main/java/io/cdap/cdap/test/TestBase.java

-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ private static CConfiguration createCconf(File localDataDir,
562562
cConf.set(Constants.Transaction.Container.ADDRESS, localhost);
563563
cConf.set(Constants.Dataset.Executor.ADDRESS, localhost);
564564
cConf.set(Constants.Metrics.ADDRESS, localhost);
565-
cConf.set(Constants.MetricsProcessor.BIND_ADDRESS, localhost);
566565
cConf.set(Constants.LogSaver.ADDRESS, localhost);
567566
cConf.set(Constants.Security.AUTH_SERVER_BIND_ADDRESS, localhost);
568567
cConf.set(Constants.Metadata.SERVICE_BIND_ADDRESS, localhost);

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/MetricsLogAppender.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected void append(ILoggingEvent eventObject) {
8181
// Don't increment metrics for logs from MetricsProcessor to avoid possibility of infinite loop
8282
if (!(metricsTags.containsKey(Constants.Metrics.Tag.COMPONENT)
8383
&& metricsTags.get(Constants.Metrics.Tag.COMPONENT)
84-
.equals(Constants.Service.METRICS_PROCESSOR))) {
84+
.equals(Constants.Service.METRICS))) {
8585
// todo this is inefficient as childContext implementation creates new map should use metricsCollectionService
8686
MetricsContext childContext = metricsContext.childContext(metricsTags);
8787
childContext.increment(metricName, 1);

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/metrics/collect/LocalMetricsCollectionService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class LocalMetricsCollectionService extends AggregatedMetricsCollec
4242

4343
private static final ImmutableMap<String, String> METRICS_PROCESSOR_CONTEXT =
4444
ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, Id.Namespace.SYSTEM.getId(),
45-
Constants.Metrics.Tag.COMPONENT, Constants.Service.METRICS_PROCESSOR);
45+
Constants.Metrics.Tag.COMPONENT, Constants.Service.METRICS);
4646

4747
private final CConfiguration cConf;
4848
private final MetricStore metricStore;

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MetricsProcessorStatusService.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public class MetricsProcessorStatusService extends AbstractIdleService {
5252
public MetricsProcessorStatusService(CConfiguration cConf, SConfiguration sConf,
5353
DiscoveryService discoveryService,
5454
@Named(Constants.MetricsProcessor.METRICS_PROCESSOR_STATUS_HANDLER)
55-
Set<HttpHandler> handlers,
55+
Set<HttpHandler> handlers,
5656
CommonNettyHttpServiceFactory commonNettyHttpServiceFactory) {
5757
this.discoveryService = discoveryService;
5858
NettyHttpService.Builder builder = commonNettyHttpServiceFactory.builder(
59-
Constants.Service.METRICS_PROCESSOR)
59+
Constants.Service.METRICS)
6060
.setHttpHandlers(handlers)
61-
.setHost(cConf.get(Constants.MetricsProcessor.BIND_ADDRESS))
62-
.setPort(cConf.getInt(Constants.MetricsProcessor.BIND_PORT));
61+
.setHost(cConf.get(Constants.Metrics.ADDRESS))
62+
.setPort(cConf.getInt(Constants.Metrics.PORT));
6363

6464
if (cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED)) {
6565
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(builder);
@@ -72,14 +72,14 @@ public MetricsProcessorStatusService(CConfiguration cConf, SConfiguration sConf,
7272
protected void startUp() throws Exception {
7373
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(),
7474
Constants.Logging.COMPONENT_NAME,
75-
Constants.Service.METRICS_PROCESSOR));
75+
Constants.Service.METRICS));
7676
LOG.info("Starting MetricsProcessor Status Service...");
7777

7878
httpService.start();
7979

8080
cancellable = discoveryService.register(
8181
ResolvingDiscoverable.of(
82-
URIScheme.createDiscoverable(Constants.Service.METRICS_PROCESSOR, httpService)));
82+
URIScheme.createDiscoverable(Constants.Service.METRICS, httpService)));
8383
LOG.info("Started MetricsProcessor Status Service.");
8484
}
8585

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/metrics/query/MetricsQueryService.java

-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class MetricsQueryService extends AbstractIdleService {
4545
private static final Logger LOG = LoggerFactory.getLogger(MetricsQueryService.class);
4646

4747
private final NettyHttpService httpService;
48-
private final Set<HttpHandler> handlers;
4948
private final DiscoveryService discoveryService;
5049
private Cancellable cancelDiscovery;
5150

@@ -54,7 +53,6 @@ public MetricsQueryService(CConfiguration cConf, SConfiguration sConf,
5453
@Named(Constants.Service.METRICS) Set<HttpHandler> handlers,
5554
DiscoveryService discoveryService,
5655
CommonNettyHttpServiceFactory commonNettyHttpServiceFactory) {
57-
this.handlers = handlers;
5856
// netty http server config
5957
String address = cConf.get(Constants.Metrics.ADDRESS);
6058
int backlogcnxs = cConf.getInt(Constants.Metrics.BACKLOG_CONNECTIONS, 20000);
@@ -111,11 +109,4 @@ protected void shutDown() throws Exception {
111109
cancelDiscovery.cancel();
112110
httpService.stop();
113111
}
114-
115-
/**
116-
* Returns the set of HTTP handlers associated.
117-
*/
118-
public Set<HttpHandler> getHandlers() {
119-
return handlers;
120-
}
121112
}

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/metrics/runtime/MetricsProcessorStatusServiceManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class MetricsProcessorStatusServiceManager extends AbstractMasterServiceM
3131
@Inject
3232
MetricsProcessorStatusServiceManager(CConfiguration cConf, TwillRunner twillRunner,
3333
DiscoveryServiceClient discoveryClient) {
34-
super(cConf, discoveryClient, Constants.Service.METRICS_PROCESSOR, twillRunner);
34+
super(cConf, discoveryClient, Constants.Service.METRICS, twillRunner);
3535
}
3636

3737
@Override

Diff for: cdap-watchdog/src/main/java/io/cdap/cdap/metrics/service/MetricsService.java

-120
This file was deleted.

0 commit comments

Comments
 (0)