private static void addSomeContext(Profiler profiler) { profiler.addContext("a_string", "bar"); profiler.addContext("null_value", null); profiler.addContext("an_int", 42); profiler.addContext("after_start", true); }
@Override public ComputationStep.Statistics add(String key, Object value) { requireNonNull(key, "Statistic has null key"); requireNonNull(value, () -> format("Statistic with key [%s] has null value", key)); checkArgument(!key.equalsIgnoreCase("time"), "Statistic with key [time] is not accepted"); checkArgument(!profiler.hasContext(key), "Statistic with key [%s] is already present", key); profiler.addContext(key, value); return this; } }
private static Profiler startLogProfiler(CeTask task) { Profiler profiler = Profiler.create(LOG) .logTimeLast(true) .addContext("project", task.getMainComponent().flatMap(CeTask.Component::getKey).orElse(null)) .addContext("type", task.getType()); for (Map.Entry<String, String> characteristic : task.getCharacteristics().entrySet()) { profiler.addContext(characteristic.getKey(), characteristic.getValue()); } return profiler .addContext("id", task.getUuid()) .addContext("submitter", submitterOf(task)) .startInfo("Execute task"); }
private static void stopLogProfiler(Profiler profiler, CeActivityDto.Status status) { profiler.addContext("status", status.name()); profiler.stopInfo("Executed task"); }
@Test public void start_writes_no_log_even_if_there_is_context() { underTest.addContext("a_string", "bar"); underTest.addContext("null_value", null); underTest.addContext("an_int", 42); underTest.start(); // do not write context as there's no message assertThat(tester.logs()).isEmpty(); }
private void executeStep(Profiler stepProfiler, ComputationStep.Context context, ComputationStep step) { String status = "FAILED"; stepProfiler.start(); try { taskInterrupter.check(Thread.currentThread()); step.execute(context); status = "SUCCESS"; } finally { stepProfiler.addContext("status", status); stepProfiler.stopInfo(step.getDescription()); } }
@Test public void hasContext() { assertThat(underTest.hasContext("foo")).isFalse(); underTest.addContext("foo", "bar"); assertThat(underTest.hasContext("foo")).isTrue(); underTest.addContext("foo", null); assertThat(underTest.hasContext("foo")).isFalse(); } }
@Test public void empty_message() { underTest.addContext("foo", "bar"); underTest.startInfo(""); assertThat(tester.logs()).containsOnly("foo=bar"); underTest.addContext("after_start", true); underTest.stopInfo(""); assertThat(tester.logs()).hasSize(2); assertThat(tester.logs().get(1)) .startsWith("time=") .endsWith("ms | foo=bar | after_start=true"); }
private static void addContext(Profiler profiler, CeTask task) { profiler .logTimeLast(true) .addContext("project", task.getComponentKey()) .addContext("type", task.getType()) .addContext("id", task.getUuid()); String submitterLogin = task.getSubmitterLogin(); if (submitterLogin != null) { profiler.addContext("submitter", submitterLogin); } } }