Search in sources :

Example 6 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class JobMetricsTest method testCustomTags.

@Test
public void testCustomTags() {
    Properties testProperties = new Properties();
    Tag<String> expectedPropertyTag = new Tag<>("key1", "value1");
    GobblinMetrics.addCustomTagToProperties(testProperties, expectedPropertyTag);
    State testState = new State(testProperties);
    List<Tag<?>> tags = GobblinMetrics.getCustomTagsFromState(testState);
    Assert.assertEquals(Iterables.getFirst(tags, null), expectedPropertyTag);
    Tag<String> expectedStateTag = new Tag<>("key2", "value2");
    GobblinMetrics.addCustomTagToState(testState, expectedStateTag);
    tags = GobblinMetrics.getCustomTagsFromState(testState);
    Assert.assertTrue(tags.containsAll(ImmutableList.of(expectedPropertyTag, expectedStateTag)));
}
Also used : JobState(org.apache.gobblin.runtime.JobState) State(org.apache.gobblin.configuration.State) Tag(org.apache.gobblin.metrics.Tag) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 7 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class JobMetricsTest method testJobMetricsGet.

@Test
public void testJobMetricsGet() {
    String jobName = "testJob";
    String jobId = "job_123";
    JobState jobState = new JobState(jobName, jobId);
    JobMetrics jobMetrics = JobMetrics.get(jobState);
    Assert.assertNotNull(jobMetrics.getMetricContext());
    List<Tag<?>> tags = jobMetrics.getMetricContext().getTags();
    Map<String, ?> tagMap = jobMetrics.getMetricContext().getTagMap();
    String contextId = tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME).toString();
    String contextName = tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME).toString();
    Assert.assertEquals(tagMap.size(), 4);
    Assert.assertEquals(tagMap.get(JobEvent.METADATA_JOB_ID), jobId);
    Assert.assertEquals(tagMap.get(JobEvent.METADATA_JOB_NAME), jobName);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
    // should get the original jobMetrics, can check by the id
    JobMetrics jobMetrics1 = JobMetrics.get(jobName + "_", jobId);
    Assert.assertNotNull(jobMetrics1.getMetricContext());
    tagMap = jobMetrics1.getMetricContext().getTagMap();
    Assert.assertEquals(tags.size(), 4);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
    // remove original jobMetrics, should create a new one
    GobblinMetricsRegistry.getInstance().remove(jobMetrics.getId());
    JobMetrics jobMetrics2 = JobMetrics.get(jobName + "_", jobId);
    Assert.assertNotNull(jobMetrics2.getMetricContext());
    tagMap = jobMetrics2.getMetricContext().getTagMap();
    Assert.assertEquals(tags.size(), 4);
    Assert.assertNotEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertNotEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
}
Also used : JobState(org.apache.gobblin.runtime.JobState) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 8 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class YarnService method buildGobblinMetrics.

private GobblinMetrics buildGobblinMetrics() {
    // Create tags list
    ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>();
    tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_ID, this.applicationId));
    tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, this.applicationName));
    // Intialize Gobblin metrics and start reporters
    GobblinMetrics gobblinMetrics = GobblinMetrics.get(this.applicationId, null, tags.build());
    gobblinMetrics.startMetricReporting(ConfigUtils.configToProperties(config));
    return gobblinMetrics;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) GobblinMetrics(org.apache.gobblin.metrics.GobblinMetrics) Tag(org.apache.gobblin.metrics.Tag)

Example 9 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class GobblinHelixJobLauncherTest method testLaunchMultipleJobs.

public void testLaunchMultipleJobs() throws Exception {
    final ConcurrentHashMap<String, Boolean> runningMap = new ConcurrentHashMap<>();
    // Job launcher(1) to test parallel job running
    final Properties properties1 = generateJobProperties(this.baseConfig, "2", "_1504201348471");
    final GobblinHelixJobLauncher gobblinHelixJobLauncher1 = this.closer.register(new GobblinHelixJobLauncher(properties1, this.helixManager, this.appWorkDir, ImmutableList.<Tag<?>>of(), runningMap));
    // Job launcher(2) to test parallel job running
    final Properties properties2 = generateJobProperties(this.baseConfig, "2", "_1504201348472");
    final GobblinHelixJobLauncher gobblinHelixJobLauncher2 = this.closer.register(new GobblinHelixJobLauncher(properties2, this.helixManager, this.appWorkDir, ImmutableList.<Tag<?>>of(), runningMap));
    CountDownLatch stg1 = new CountDownLatch(1);
    CountDownLatch stg2 = new CountDownLatch(1);
    CountDownLatch stg3 = new CountDownLatch(1);
    SuspendJobListener testListener = new SuspendJobListener(stg1, stg2);
    (new Thread(() -> {
        try {
            gobblinHelixJobLauncher1.launchJob(testListener);
            stg3.countDown();
        } catch (JobException e) {
        }
    })).start();
    // Wait for the first job to start
    stg1.await();
    // When first job is in the middle of running, launch the second job (which should do NOOP because previous job is still running)
    gobblinHelixJobLauncher2.launchJob(testListener);
    stg2.countDown();
    // Wait for the first job to finish
    stg3.await();
    Assert.assertEquals(testListener.getCompletes().get() == 1, true);
}
Also used : JobException(org.apache.gobblin.runtime.JobException) Tag(org.apache.gobblin.metrics.Tag) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class GobblinHelixJobLauncherTest method testLaunchJob.

public void testLaunchJob() throws Exception {
    final ConcurrentHashMap<String, Boolean> runningMap = new ConcurrentHashMap<>();
    // Normal job launcher
    final Properties properties = generateJobProperties(this.baseConfig, "1", "_1504201348470");
    final GobblinHelixJobLauncher gobblinHelixJobLauncher = this.closer.register(new GobblinHelixJobLauncher(properties, this.helixManager, this.appWorkDir, ImmutableList.<Tag<?>>of(), runningMap));
    gobblinHelixJobLauncher.launchJob(null);
    final File jobOutputFile = getJobOutputFile(properties);
    Assert.assertTrue(jobOutputFile.exists());
    Schema schema = new Schema.Parser().parse(TestHelper.SOURCE_SCHEMA);
    TestHelper.assertGenericRecords(jobOutputFile, schema);
    List<JobState.DatasetState> datasetStates = this.datasetStateStore.getAll(properties.getProperty(ConfigurationKeys.JOB_NAME_KEY), FsDatasetStateStore.CURRENT_DATASET_STATE_FILE_SUFFIX + FsDatasetStateStore.DATASET_STATE_STORE_TABLE_SUFFIX);
    Assert.assertEquals(datasetStates.size(), 1);
    JobState.DatasetState datasetState = datasetStates.get(0);
    Assert.assertEquals(datasetState.getCompletedTasks(), 1);
    Assert.assertEquals(datasetState.getState(), JobState.RunningState.COMMITTED);
    Assert.assertEquals(datasetState.getTaskStates().size(), 1);
    Assert.assertEquals(datasetState.getTaskStates().get(0).getWorkingState(), WorkUnitState.WorkingState.COMMITTED);
}
Also used : Schema(org.apache.avro.Schema) Properties(java.util.Properties) JobState(org.apache.gobblin.runtime.JobState) Tag(org.apache.gobblin.metrics.Tag) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) File(java.io.File)

Aggregations

Tag (org.apache.gobblin.metrics.Tag)13 Properties (java.util.Properties)7 MetricContext (org.apache.gobblin.metrics.MetricContext)7 Test (org.testng.annotations.Test)7 Counter (com.codahale.metrics.Counter)4 GobblinMetrics (org.apache.gobblin.metrics.GobblinMetrics)3 JobState (org.apache.gobblin.runtime.JobState)3 Gauge (com.codahale.metrics.Gauge)2 Histogram (com.codahale.metrics.Histogram)2 Meter (com.codahale.metrics.Meter)2 Timer (com.codahale.metrics.Timer)2 ImmutableList (com.google.common.collect.ImmutableList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ContextAwareGauge (org.apache.gobblin.metrics.ContextAwareGauge)2 MetricReport (org.apache.gobblin.metrics.MetricReport)2 KafkaReporter (org.apache.gobblin.metrics.kafka.KafkaReporter)2 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Schema (org.apache.avro.Schema)1 Constructs (org.apache.gobblin.Constructs)1