private boolean lockDag(@NotEmpty final String jobName, @NotEmpty final String dagName) { final String key = LockManager.getLockKey(DAG_LOCK_KEY, dagName); final TimerMetric timerMetric = new TimerMetric(JobMetricNames.JOB_DAG_LOCK_TIME_MS, ImmutableMap.of( JOB_FREQUENCY_TAG, jobFrequency, JOB_NAME_TAG, jobName, DATA_FEED_TAG, dagName)); final boolean success = lockManager.lock(key, String.format("JobDag %s AppId %s", dagName, appId)); timerMetric.stop(); dagTimerMetricMap.put(dagName, timerMetric); return success; }
public void stop() { if (!this.stopped) { this.endTime = Instant.now(); calculateElapsed(); this.stopped = true; } }
public TimerMetric createTimerMetric(@NonNull final String metricName, @NonNull final Map<String, String> additionalTags, @NonNull final Optional<Instant> startTime) { final TimerMetric metric = startTime.isPresent() ? new TimerMetric(metricName, additionalTags, startTime.get()) : new TimerMetric(metricName); metric.addTags(getBaseTags()); metric.addTags(additionalTags); metricSet.add(metric); return metric; }
} finally { timerMetric.stop(); reportStatus(successful.get()); if (getJobManagerMetadata() != null && successful.get()) { this.getJobManagerMetadata().put(LAST_RUNTIME_METADATA_KEY, timerMetric.getMetricValue().toString()); this.getJobManagerMetadata().put(LAST_EXECUTION_METADATA_KEY, String.valueOf(TimeUnit.SECONDS.toMillis(timerMetric.getStartTime().getEpochSecond())));
@Test public void testGetMetricValueSuccess() throws InterruptedException { Thread.sleep(SLEEP_TIME); this.timerMetric.stop(); long diff = this.timerMetric.getMetricValue() - SLEEP_TIME; assertTrue(diff < THRESHOLD); }
public TimerMetric(@NotEmpty final String metricName) { super(metricName); this.addTag("metric-type", "timer"); this.startTime = Instant.now(); }
@Before public void setupTestClass() { this.timerMetric = new TimerMetric("timer-big-function"); }
@Test(expected=JobRuntimeException.class) public void testGetMetricValueFail() { timerMetric.getMetricValue(); }
public TimerMetric(@NotEmpty final String metricName, @NonNull final Map<String, String> tags) { this(metricName.toString()); this.addTags(tags); }
public TimerMetric createTimerMetric(@NonNull final String metricName) { final TimerMetric metric = new TimerMetric(metricName); metric.addTags(getBaseTags()); metricSet.add(metric); return metric; }
private JobLockManager(@NonNull final Configuration conf, @NotEmpty final String frequency, final boolean shouldLockFrequency) { this.lockManager = new LockManager(conf); this.jobFrequency = frequency; final String key = LockManager.getLockKey(MANAGER_LOCK_KEY, jobFrequency); this.managerTimerMetric = new TimerMetric(JobMetricNames.JOB_MANAGER_LOCK_TIME_MS, ImmutableMap.of(JOB_FREQUENCY_TAG, jobFrequency, JOB_NAME_TAG, appName)); if (shouldLockFrequency) { final boolean success = lockManager.lock(key, String.format("JobManager %s AppId %s", jobFrequency, appId)); this.managerTimerMetric.stop(); if (!success) { lockManager.close(); throw new IllegalStateException("Failed to obtain lock for JobManager " + jobFrequency); } } else { managerTimerMetric.stop(); log.info("Frequency lock disabled"); } this.dagTimerMetricMap = new HashMap<>(); }
public TimerMetric createJobTimerMetric(@NonNull final JobMetricType metricType, @NonNull final Map<String, String> additionalTags) { final TimerMetric metric = new TimerMetric(getMetricName(metricType)); metric.addTags(getBaseTags()); metric.addTags(additionalTags); metricSet.add(metric); return metric; }