@Test public void shouldRetainLastRetainActivityLogs() throws Exception { JaegerActivityTrackingService service = new JaegerActivityTrackingService(new JaegerQueryAPI("http: @Override public List<Trace> tracesForService(String service, int lookbackDays, int limit) { try { String json = resource("example-jaeger-trace-result.json"); Traces traces = JsonUtils.reader().forType(Traces.class).readValue(json); return traces.data; } catch (IOException e) { throw new WebApplicationException(e); } } }); List<Activity> activities = service.getActivities("test", null, null); assertThat(activities).isNotNull(); String activitiesJson = JsonUtils.writer().withDefaultPrettyPrinter().writeValueAsString(activities).trim(); String expectedActivitiesJson = resource("expected-activities.json").trim(); assertThatJson(activitiesJson).isEqualTo(expectedActivitiesJson); }
@Override @SuppressWarnings({"PMD.NPathComplexity"}) public List<Activity> getActivities(String integrationId, String from, Integer requestedLimit) { int lookbackDays = 30; int limit = 10; if (requestedLimit != null) { limit = requestedLimit; } if (limit > 1000) { limit = 1000; } List<JaegerQueryAPI.Trace> traces = jaegerQueryApi.tracesForService(integrationId, lookbackDays, limit); ArrayList<Activity> rc = new ArrayList<>(); for (JaegerQueryAPI.Trace trace : traces) { Activity activity = null; ArrayList<ActivityStep> steps = new ArrayList<>(); if (trace.spans != null && trace.spans.size() >= 1) { for (JaegerQueryAPI.Span span : trace.spans) { String kind = span.findTag(Tags.SPAN_KIND.getKey(), String.class); if (kind == null) { LOG.debug("Cannot find tag 'span.kind' in trace: {} and span: {}", trace.traceID, span); continue; } switch (kind) { case "activity": { activity = new Activity(); activity.setId(trace.traceID); JaegerQueryAPI.JaegerProcess process = trace.processes.get(span.processID); String version = process.findTag("integration.version", String.class); activity.setVer(version); String hostname = process.findTag("hostname", String.class); activity.setPod(hostname); activity.setStatus("done"); activity.setAt(span.startTime/1000); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null) { activity.setFailed(failed); } } break; case "step": { ActivityStep step = new ActivityStep(); step.setId(span.operationName); step.setAt(span.startTime); step.setDuration(span.duration*1000); List<String> messages = span.findLogs("event"); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null && failed) { String msg = messages != null && !messages.isEmpty() ? messages.get(0) : ""; step.setFailure(msg); } else { step.setMessages(messages); } steps.add(step); } break; default: LOG.debug("Unknown span: " + span); break; } } } if (activity != null) { steps.sort(Comparator.comparing(ActivityStep::getAt)); for (ActivityStep step: steps) { step.setAt(step.getAt()/1000); } activity.setSteps(steps); rc.add(activity); } } rc.sort(Comparator.comparing(Activity::getAt)); Collections.reverse(rc); return rc; }
JaegerActivityTrackingService implements ActivityTrackingService { @Override @SuppressWarnings({"PMD.NPathComplexity"}) public List<Activity> getActivities(String integrationId, String from, Integer requestedLimit) { int lookbackDays = 30; int limit = 10; if (requestedLimit != null) { limit = requestedLimit; } if (limit > 1000) { limit = 1000; } List<JaegerQueryAPI.Trace> traces = jaegerQueryApi.tracesForService(integrationId, lookbackDays, limit); ArrayList<Activity> rc = new ArrayList<>(); for (JaegerQueryAPI.Trace trace : traces) { Activity activity = null; ArrayList<ActivityStep> steps = new ArrayList<>(); if (trace.spans != null && trace.spans.size() >= 1) { for (JaegerQueryAPI.Span span : trace.spans) { String kind = span.findTag(Tags.SPAN_KIND.getKey(), String.class); if (kind == null) { LOG.debug("Cannot find tag 'span.kind' in trace: {} and span: {}", trace.traceID, span); continue; } switch (kind) { case "activity": { activity = new Activity(); activity.setId(trace.traceID); JaegerQueryAPI.JaegerProcess process = trace.processes.get(span.processID); String version = process.findTag("integration.version", String.class); activity.setVer(version); String hostname = process.findTag("hostname", String.class); activity.setPod(hostname); activity.setStatus("done"); activity.setAt(span.startTime/1000); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null) { activity.setFailed(failed); } } break; case "step": { ActivityStep step = new ActivityStep(); step.setId(span.operationName); step.setAt(span.startTime); step.setDuration(span.duration*1000); List<String> messages = span.findLogs("event"); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null && failed) { String msg = messages != null && !messages.isEmpty() ? messages.get(0) : ""; step.setFailure(msg); } else { step.setMessages(messages); } steps.add(step); } break; default: LOG.debug("Unknown span: " + span); break; } } } if (activity != null) { steps.sort(Comparator.comparing(ActivityStep::getAt)); for (ActivityStep step: steps) { step.setAt(step.getAt()/1000); } activity.setSteps(steps); rc.add(activity); } } rc.sort(Comparator.comparing(Activity::getAt)); Collections.reverse(rc); return rc; } }
JaegerActivityTrackingService implements ActivityTrackingService { @Override @SuppressWarnings({"PMD.NPathComplexity"}) public List<Activity> getActivities(String integrationId, String from, Integer requestedLimit) { int lookbackDays = 30; int limit = 10; if (requestedLimit != null) { limit = requestedLimit; } if (limit > 1000) { limit = 1000; } List<JaegerQueryAPI.Trace> traces = jaegerQueryApi.tracesForService(integrationId, lookbackDays, limit); ArrayList<Activity> rc = new ArrayList<>(); for (JaegerQueryAPI.Trace trace : traces) { Activity activity = null; ArrayList<ActivityStep> steps = new ArrayList<>(); if (trace.spans != null && trace.spans.size() >= 1) { for (JaegerQueryAPI.Span span : trace.spans) { String kind = span.findTag(Tags.SPAN_KIND.getKey(), String.class); if (kind == null) { LOG.debug("Cannot find tag 'span.kind' in trace: {} and span: {}", trace.traceID, span); continue; } switch (kind) { case "activity": { activity = new Activity(); activity.setId(trace.traceID); JaegerQueryAPI.JaegerProcess process = trace.processes.get(span.processID); String version = process.findTag("integration.version", String.class); activity.setVer(version); String hostname = process.findTag("hostname", String.class); activity.setPod(hostname); activity.setStatus("done"); activity.setAt(span.startTime/1000); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null) { activity.setFailed(failed); } } break; case "step": { ActivityStep step = new ActivityStep(); step.setId(span.operationName); step.setAt(span.startTime); step.setDuration(span.duration*1000); List<String> messages = span.findLogs("event"); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null && failed) { String msg = messages != null && !messages.isEmpty() ? messages.get(0) : ""; step.setFailure(msg); } else { step.setMessages(messages); } steps.add(step); } break; default: LOG.debug("Unknown span: " + span); break; } } } if (activity != null) { steps.sort(Comparator.comparing(ActivityStep::getAt)); for (ActivityStep step: steps) { step.setAt(step.getAt()/1000); } activity.setSteps(steps); rc.add(activity); } } rc.sort(Comparator.comparing(Activity::getAt)); Collections.reverse(rc); return rc; } JaegerActivityTrackingService(JaegerQueryAPI jaegerQueryApi); }
JaegerActivityTrackingService implements ActivityTrackingService { @Override @SuppressWarnings({"PMD.NPathComplexity"}) public List<Activity> getActivities(String integrationId, String from, Integer requestedLimit) { int lookbackDays = 30; int limit = 10; if (requestedLimit != null) { limit = requestedLimit; } if (limit > 1000) { limit = 1000; } List<JaegerQueryAPI.Trace> traces = jaegerQueryApi.tracesForService(integrationId, lookbackDays, limit); ArrayList<Activity> rc = new ArrayList<>(); for (JaegerQueryAPI.Trace trace : traces) { Activity activity = null; ArrayList<ActivityStep> steps = new ArrayList<>(); if (trace.spans != null && trace.spans.size() >= 1) { for (JaegerQueryAPI.Span span : trace.spans) { String kind = span.findTag(Tags.SPAN_KIND.getKey(), String.class); if (kind == null) { LOG.debug("Cannot find tag 'span.kind' in trace: {} and span: {}", trace.traceID, span); continue; } switch (kind) { case "activity": { activity = new Activity(); activity.setId(trace.traceID); JaegerQueryAPI.JaegerProcess process = trace.processes.get(span.processID); String version = process.findTag("integration.version", String.class); activity.setVer(version); String hostname = process.findTag("hostname", String.class); activity.setPod(hostname); activity.setStatus("done"); activity.setAt(span.startTime/1000); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null) { activity.setFailed(failed); } } break; case "step": { ActivityStep step = new ActivityStep(); step.setId(span.operationName); step.setAt(span.startTime); step.setDuration(span.duration*1000); List<String> messages = span.findLogs("event"); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null && failed) { String msg = messages != null && !messages.isEmpty() ? messages.get(0) : ""; step.setFailure(msg); } else { step.setMessages(messages); } steps.add(step); } break; default: LOG.debug("Unknown span: " + span); break; } } } if (activity != null) { steps.sort(Comparator.comparing(ActivityStep::getAt)); for (ActivityStep step: steps) { step.setAt(step.getAt()/1000); } activity.setSteps(steps); rc.add(activity); } } rc.sort(Comparator.comparing(Activity::getAt)); Collections.reverse(rc); return rc; } JaegerActivityTrackingService(JaegerQueryAPI jaegerQueryApi); @Override @SuppressWarnings({"PMD.NPathComplexity"}) List<Activity> getActivities(String integrationId, String from, Integer requestedLimit); }
JaegerActivityTrackingService implements ActivityTrackingService { @Override @SuppressWarnings({"PMD.NPathComplexity"}) public List<Activity> getActivities(String integrationId, String from, Integer requestedLimit) { int lookbackDays = 30; int limit = 10; if (requestedLimit != null) { limit = requestedLimit; } if (limit > 1000) { limit = 1000; } List<JaegerQueryAPI.Trace> traces = jaegerQueryApi.tracesForService(integrationId, lookbackDays, limit); ArrayList<Activity> rc = new ArrayList<>(); for (JaegerQueryAPI.Trace trace : traces) { Activity activity = null; ArrayList<ActivityStep> steps = new ArrayList<>(); if (trace.spans != null && trace.spans.size() >= 1) { for (JaegerQueryAPI.Span span : trace.spans) { String kind = span.findTag(Tags.SPAN_KIND.getKey(), String.class); if (kind == null) { LOG.debug("Cannot find tag 'span.kind' in trace: {} and span: {}", trace.traceID, span); continue; } switch (kind) { case "activity": { activity = new Activity(); activity.setId(trace.traceID); JaegerQueryAPI.JaegerProcess process = trace.processes.get(span.processID); String version = process.findTag("integration.version", String.class); activity.setVer(version); String hostname = process.findTag("hostname", String.class); activity.setPod(hostname); activity.setStatus("done"); activity.setAt(span.startTime/1000); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null) { activity.setFailed(failed); } } break; case "step": { ActivityStep step = new ActivityStep(); step.setId(span.operationName); step.setAt(span.startTime); step.setDuration(span.duration*1000); List<String> messages = span.findLogs("event"); Boolean failed = span.findTag(Tags.ERROR.getKey(), Boolean.class); if (failed != null && failed) { String msg = messages != null && !messages.isEmpty() ? messages.get(0) : ""; step.setFailure(msg); } else { step.setMessages(messages); } steps.add(step); } break; default: LOG.debug("Unknown span: " + span); break; } } } if (activity != null) { steps.sort(Comparator.comparing(ActivityStep::getAt)); for (ActivityStep step: steps) { step.setAt(step.getAt()/1000); } activity.setSteps(steps); rc.add(activity); } } rc.sort(Comparator.comparing(Activity::getAt)); Collections.reverse(rc); return rc; } JaegerActivityTrackingService(JaegerQueryAPI jaegerQueryApi); @Override @SuppressWarnings({"PMD.NPathComplexity"}) List<Activity> getActivities(String integrationId, String from, Integer requestedLimit);  }