Search in sources :

Example 6 with MetricsCollectionService

use of io.cdap.cdap.api.metrics.MetricsCollectionService in project cdap by caskdata.

the class ProfileMetricServiceTest method testProfileMetrics.

@Test
public void testProfileMetrics() throws Exception {
    ProgramRunId runId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram").run(RunIds.generate());
    ProfileId profileId = NamespaceId.DEFAULT.profile("myProfile");
    MetricsCollectionService collectionService = injector.getInstance(MetricsCollectionService.class);
    MetricStore metricStore = injector.getInstance(MetricStore.class);
    // There are 5 nodes, we emit the metrics each 2 mins, so each time the node minute should go up by 10 min
    ProfileMetricService scheduledService = new ProfileMetricService(collectionService, runId, profileId, 5, 2);
    // emit and verify the results
    scheduledService.emitMetric();
    Tasks.waitFor(10L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
    scheduledService.emitMetric();
    Tasks.waitFor(20L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
    scheduledService.emitMetric();
    Tasks.waitFor(30L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) MetricStore(io.cdap.cdap.api.metrics.MetricStore) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 7 with MetricsCollectionService

use of io.cdap.cdap.api.metrics.MetricsCollectionService in project cdap by caskdata.

the class ProfileMetricServiceTest method testRoundingLogic.

@Test
public void testRoundingLogic() throws Exception {
    ProgramRunId runId = NamespaceId.DEFAULT.app("round").workflow("round").run(RunIds.generate());
    ProfileId profileId = NamespaceId.DEFAULT.profile("roundProfile");
    MetricsCollectionService collectionService = injector.getInstance(MetricsCollectionService.class);
    MetricStore metricStore = injector.getInstance(MetricStore.class);
    ProfileMetricService scheduledService = new ProfileMetricService(collectionService, runId, profileId, 1, 1);
    // start and stop the service, the metric should still go up by 1
    scheduledService.startUp();
    scheduledService.shutDown();
    Tasks.waitFor(1L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
    scheduledService.startUp();
    // set the start up time to 90 seconds before the current time
    scheduledService.setStartUpTime(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - 90);
    // 90 seconds should round up to 2 mins, so emit 1 min and test the rounding logic
    scheduledService.emitMetric();
    scheduledService.shutDown();
    // the metric should go up by 2
    Tasks.waitFor(3L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
    scheduledService.startUp();
    // set the start up time to 65 seconds before the current time
    scheduledService.setStartUpTime(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - 65);
    // 65 seconds should round down to 1 min, so emit 1 min and test the rest seconds are ignored
    scheduledService.emitMetric();
    scheduledService.shutDown();
    // the metric should go up by 1
    Tasks.waitFor(4L, () -> getMetric(metricStore, runId, profileId, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) MetricStore(io.cdap.cdap.api.metrics.MetricStore) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 8 with MetricsCollectionService

use of io.cdap.cdap.api.metrics.MetricsCollectionService in project cdap by caskdata.

the class ProgramStatusEventPublisherMetricsTest method testMetrics.

@Test
public void testMetrics() throws IOException {
    MetricsProvider mockMetricsProvider = getMockMetricsProvider();
    List<MetricValues> metricValuesList = new ArrayList<>();
    MetricsCollectionService mockMetricsCollectionService = getMockCollectionService(metricValuesList);
    mockMetricsCollectionService.startAndWait();
    ProgramStatusEventPublisher programStatusEventPublisher = new ProgramStatusEventPublisher(CConfiguration.create(), null, mockMetricsCollectionService, null, mockMetricsProvider);
    programStatusEventPublisher.initialize(Collections.singleton(new DummyEventWriter()));
    programStatusEventPublisher.processMessages(null, getMockNotification());
    mockMetricsCollectionService.stopAndWait();
    Assert.assertSame(1, metricValuesList.size());
    Assert.assertTrue(containsMetric(metricValuesList.get(0), Constants.Metrics.ProgramEvent.PUBLISHED_COUNT));
}
Also used : DummyEventWriter(io.cdap.cdap.internal.events.dummy.DummyEventWriter) AggregatedMetricsCollectionService(io.cdap.cdap.metrics.collect.AggregatedMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ArrayList(java.util.ArrayList) MetricValues(io.cdap.cdap.api.metrics.MetricValues) Test(org.junit.Test)

Example 9 with MetricsCollectionService

use of io.cdap.cdap.api.metrics.MetricsCollectionService in project cdap by caskdata.

the class MetricsReporterHookTest method testReponseTimeCollection.

@Test
public void testReponseTimeCollection() throws InterruptedException {
    MetricsContext mockCollector = mock(MetricsContext.class);
    MetricsCollectionService mockCollectionService = mock(MetricsCollectionService.class);
    when(mockCollectionService.getContext(anyMap())).thenReturn(mockCollector);
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://ignore");
    HandlerInfo handlerInfo = new HandlerInfo(TESTHANDLERNAME, TESTMETHODNAME);
    MetricsReporterHook hook = new MetricsReporterHook(CConfiguration.create(), mockCollectionService, TESTSERVICENAME);
    hook.preCall(request, null, handlerInfo);
    hook.postCall(request, HttpResponseStatus.OK, handlerInfo);
    verify(mockCollector).event(eq("response.latency"), anyLong());
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) MetricsContext(io.cdap.cdap.api.metrics.MetricsContext) HandlerInfo(io.cdap.http.internal.HandlerInfo) Test(org.junit.Test)

Example 10 with MetricsCollectionService

use of io.cdap.cdap.api.metrics.MetricsCollectionService in project cdap by caskdata.

the class SparkProgramRunner method run.

@Override
public ProgramController run(Program program, ProgramOptions options) {
    LOG.trace("Starting Spark program {} with SparkProgramRunner of ClassLoader {}", program.getId(), getClass().getClassLoader());
    // Get the RunId first. It is used for the creation of the ClassLoader closing thread.
    Arguments arguments = options.getArguments();
    RunId runId = ProgramRunners.getRunId(options);
    Deque<Closeable> closeables = new LinkedList<>();
    try {
        // Extract and verify parameters
        ApplicationSpecification appSpec = program.getApplicationSpecification();
        Preconditions.checkNotNull(appSpec, "Missing application specification.");
        ProgramType processorType = program.getType();
        Preconditions.checkNotNull(processorType, "Missing processor type.");
        Preconditions.checkArgument(processorType == ProgramType.SPARK, "Only Spark process type is supported.");
        SparkSpecification spec = appSpec.getSpark().get(program.getName());
        Preconditions.checkNotNull(spec, "Missing SparkSpecification for %s", program.getName());
        String host = options.getArguments().getOption(ProgramOptionConstants.HOST);
        Preconditions.checkArgument(host != null, "No hostname is provided");
        // Get the WorkflowProgramInfo if it is started by Workflow
        WorkflowProgramInfo workflowInfo = WorkflowProgramInfo.create(arguments);
        DatasetFramework programDatasetFramework = workflowInfo == null ? datasetFramework : NameMappedDatasetFramework.createFromWorkflowProgramInfo(datasetFramework, workflowInfo, appSpec);
        // Setup dataset framework context, if required
        if (programDatasetFramework instanceof ProgramContextAware) {
            ProgramId programId = program.getId();
            ((ProgramContextAware) programDatasetFramework).setContext(new BasicProgramContext(programId.run(runId)));
        }
        PluginInstantiator pluginInstantiator = createPluginInstantiator(options, program.getClassLoader());
        if (pluginInstantiator != null) {
            closeables.addFirst(pluginInstantiator);
        }
        SparkRuntimeContext runtimeContext = new SparkRuntimeContext(new Configuration(hConf), program, options, cConf, host, txClient, programDatasetFramework, metricsCollectionService, workflowInfo, pluginInstantiator, secureStore, secureStoreManager, accessEnforcer, authenticationContext, messagingService, serviceAnnouncer, pluginFinder, locationFactory, metadataReader, metadataPublisher, namespaceQueryAdmin, fieldLineageWriter, remoteClientFactory, () -> {
        });
        closeables.addFirst(runtimeContext);
        Spark spark;
        try {
            spark = new InstantiatorFactory(false).get(TypeToken.of(program.<Spark>getMainClass())).create();
        } catch (Exception e) {
            LOG.error("Failed to instantiate Spark class for {}", spec.getClassName(), e);
            throw Throwables.propagate(e);
        }
        boolean isLocal = SparkRuntimeContextConfig.isLocal(options);
        SparkSubmitter submitter;
        // If MasterEnvironment is not available, use non-master env spark submitters
        MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
        if (masterEnv != null && cConf.getBoolean(Constants.Environment.PROGRAM_SUBMISSION_MASTER_ENV_ENABLED, true)) {
            submitter = new MasterEnvironmentSparkSubmitter(cConf, locationFactory, host, runtimeContext, masterEnv, options);
        } else {
            submitter = isLocal ? new LocalSparkSubmitter() : new DistributedSparkSubmitter(hConf, locationFactory, host, runtimeContext, options.getArguments().getOption(Constants.AppFabric.APP_SCHEDULER_QUEUE));
        }
        Service sparkRuntimeService = new SparkRuntimeService(cConf, spark, getPluginArchive(options), runtimeContext, submitter, locationFactory, isLocal, fieldLineageWriter, masterEnv, commonNettyHttpServiceFactory);
        sparkRuntimeService.addListener(createRuntimeServiceListener(closeables), Threads.SAME_THREAD_EXECUTOR);
        ProgramController controller = new SparkProgramController(sparkRuntimeService, runtimeContext);
        LOG.debug("Starting Spark Job. Context: {}", runtimeContext);
        if (isLocal || UserGroupInformation.isSecurityEnabled()) {
            sparkRuntimeService.start();
        } else {
            ProgramRunners.startAsUser(cConf.get(Constants.CFG_HDFS_USER), sparkRuntimeService);
        }
        return controller;
    } catch (Throwable t) {
        closeAllQuietly(closeables);
        throw Throwables.propagate(t);
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MasterEnvironmentSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.MasterEnvironmentSparkSubmitter) MasterEnvironmentSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.MasterEnvironmentSparkSubmitter) LocalSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.LocalSparkSubmitter) SparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.SparkSubmitter) DistributedSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.DistributedSparkSubmitter) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Closeable(java.io.Closeable) DistributedSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.DistributedSparkSubmitter) DatasetFramework(io.cdap.cdap.data2.dataset2.DatasetFramework) NameMappedDatasetFramework(io.cdap.cdap.internal.app.runtime.workflow.NameMappedDatasetFramework) InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) SparkSpecification(io.cdap.cdap.api.spark.SparkSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) RunId(org.apache.twill.api.RunId) ProgramController(io.cdap.cdap.app.runtime.ProgramController) Arguments(io.cdap.cdap.app.runtime.Arguments) MessagingService(io.cdap.cdap.messaging.MessagingService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ProgramId(io.cdap.cdap.proto.id.ProgramId) BasicProgramContext(io.cdap.cdap.internal.app.runtime.BasicProgramContext) LinkedList(java.util.LinkedList) IOException(java.io.IOException) WorkflowProgramInfo(io.cdap.cdap.internal.app.runtime.workflow.WorkflowProgramInfo) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) PluginInstantiator(io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator) Spark(io.cdap.cdap.api.spark.Spark) LocalSparkSubmitter(io.cdap.cdap.app.runtime.spark.submit.LocalSparkSubmitter) ProgramContextAware(io.cdap.cdap.data.ProgramContextAware)

Aggregations

MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)50 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 Service (com.google.common.util.concurrent.Service)20 MessagingService (io.cdap.cdap.messaging.MessagingService)20 Test (org.junit.Test)18 Configuration (org.apache.hadoop.conf.Configuration)14 Injector (com.google.inject.Injector)12 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)12 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)12 MetricStore (io.cdap.cdap.api.metrics.MetricStore)10 ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)10 File (java.io.File)10 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)8 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)8 ProfileId (io.cdap.cdap.proto.id.ProfileId)8 LinkedList (java.util.LinkedList)8 LocationFactory (org.apache.twill.filesystem.LocationFactory)8 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)7