-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate Metrics Query and Metrics Proccessor Services
- Loading branch information
1 parent
ea42fd0
commit fb804c6
Showing
7 changed files
with
146 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
cdap-watchdog/src/main/java/io/cdap/cdap/metrics/service/MetricsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright © 2025 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.metrics.service; | ||
|
||
import com.google.common.util.concurrent.AbstractIdleService; | ||
import com.google.inject.Inject; | ||
import io.cdap.cdap.common.conf.CConfiguration; | ||
import io.cdap.cdap.common.conf.Constants; | ||
import io.cdap.cdap.common.conf.SConfiguration; | ||
import io.cdap.cdap.common.discovery.ResolvingDiscoverable; | ||
import io.cdap.cdap.common.discovery.URIScheme; | ||
import io.cdap.cdap.common.http.CommonNettyHttpServiceFactory; | ||
import io.cdap.cdap.common.id.Id; | ||
import io.cdap.cdap.common.logging.LoggingContextAccessor; | ||
import io.cdap.cdap.common.logging.ServiceLoggingContext; | ||
import io.cdap.cdap.common.security.HttpsEnabler; | ||
import io.cdap.cdap.metrics.query.MetricsQueryService; | ||
import io.cdap.http.HttpHandler; | ||
import io.cdap.http.NettyHttpService; | ||
import java.util.Set; | ||
import org.apache.twill.common.Cancellable; | ||
import org.apache.twill.discovery.DiscoveryService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Metrics implemented using the common http netty framework. | ||
*/ | ||
public class MetricsService extends AbstractIdleService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MetricsService.class); | ||
|
||
private final NettyHttpService httpService; | ||
private final DiscoveryService discoveryService; | ||
private final MetricsQueryService metricsQueryService; | ||
private Cancellable cancelDiscovery; | ||
|
||
@Inject | ||
public MetricsService(CConfiguration cConf, SConfiguration sConf, | ||
MetricsQueryService metricsQueryService, | ||
DiscoveryService discoveryService, | ||
CommonNettyHttpServiceFactory commonNettyHttpServiceFactory) { | ||
this.metricsQueryService = metricsQueryService; | ||
// netty http server config | ||
String address = cConf.get(Constants.Metrics.ADDRESS); | ||
int backlogcnxs = cConf.getInt(Constants.Metrics.BACKLOG_CONNECTIONS, 20000); | ||
int execthreads = cConf.getInt(Constants.Metrics.EXEC_THREADS, 20); | ||
int bossthreads = cConf.getInt(Constants.Metrics.BOSS_THREADS, 1); | ||
int workerthreads = cConf.getInt(Constants.Metrics.WORKER_THREADS, 10); | ||
Set<HttpHandler> handlers = metricsQueryService.getHandlers(); | ||
|
||
NettyHttpService.Builder builder = commonNettyHttpServiceFactory.builder( | ||
Constants.Service.METRICS) | ||
.setHttpHandlers(handlers) | ||
.setHost(address) | ||
.setPort(cConf.getInt(Constants.Metrics.PORT)) | ||
.setConnectionBacklog(backlogcnxs) | ||
.setExecThreadPoolSize(execthreads) | ||
.setBossThreadPoolSize(bossthreads) | ||
.setWorkerThreadPoolSize(workerthreads); | ||
|
||
if (cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED)) { | ||
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(builder); | ||
} | ||
|
||
this.httpService = builder.build(); | ||
this.discoveryService = discoveryService; | ||
|
||
LOG.info("Configuring MetricsService " | ||
+ ", address: " + address | ||
+ ", backlog connections: " + backlogcnxs | ||
+ ", execthreads: " + execthreads | ||
+ ", bossthreads: " + bossthreads | ||
+ ", workerthreads: " + workerthreads); | ||
} | ||
|
||
@Override | ||
protected void startUp() throws Exception { | ||
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(Id.Namespace.SYSTEM.getId(), | ||
Constants.Logging.COMPONENT_NAME, | ||
Constants.Service.METRICS)); | ||
|
||
LOG.info("Starting Metrics Service..."); | ||
httpService.start(); | ||
LOG.info("Started Metrics HTTP Service..."); | ||
// Register the service | ||
cancelDiscovery = discoveryService.register( | ||
ResolvingDiscoverable.of( | ||
URIScheme.createDiscoverable(Constants.Service.METRICS, httpService))); | ||
LOG.info("Metrics Service started successfully on {}", httpService.getBindAddress()); | ||
} | ||
|
||
@Override | ||
protected void shutDown() throws Exception { | ||
LOG.info("Stopping Metrics Service..."); | ||
|
||
// Unregister the service | ||
try { | ||
if (cancelDiscovery != null) { | ||
cancelDiscovery.cancel(); | ||
} | ||
} finally { | ||
httpService.stop(); | ||
} | ||
} | ||
} |