mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-16 17:34:52 -06:00
add span semantics to general annotation
This commit is contained in:
parent
a9a1994527
commit
9ca1a47b64
@ -23,7 +23,7 @@ import java.util.function.Supplier;
|
||||
public class GrafanaMetricsAnnotator implements Annotator, ConfigAware {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger("ANNOTATORS" );
|
||||
private final static Logger annotationsLog = LogManager.getLogger("ANNOTATIONS" );
|
||||
//private final static Logger annotationsLog = LogManager.getLogger("ANNOTATIONS" );
|
||||
private OnError onError = OnError.Warn;
|
||||
|
||||
private GrafanaClient client;
|
||||
@ -45,9 +45,15 @@ public class GrafanaMetricsAnnotator implements Annotator, ConfigAware {
|
||||
});
|
||||
ga.getTags().add("layer:" + annotation.getLayer().toString());
|
||||
|
||||
if (annotation.getStart() == annotation.getEnd()) {
|
||||
ga.getTags().add("span:instant");
|
||||
} else {
|
||||
ga.getTags().add("span:interval");
|
||||
}
|
||||
|
||||
Map<String, String> labels = annotation.getLabels();
|
||||
|
||||
Optional.ofNullable(labels.get("alertId" ))
|
||||
Optional.ofNullable(labels.get("alertId"))
|
||||
.map(Integer::parseInt).ifPresent(ga::setAlertId);
|
||||
|
||||
ga.setText(annotation.toString());
|
||||
@ -82,7 +88,6 @@ public class GrafanaMetricsAnnotator implements Annotator, ConfigAware {
|
||||
|
||||
// Details
|
||||
|
||||
annotationsLog.info("ANNOTATION:" + ga.toString());
|
||||
GrafanaAnnotation created = this.client.createAnnotation(ga);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -73,4 +73,12 @@ public interface Annotation {
|
||||
return new AnnotationBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* This should return {@link Span#interval} if the span of time is not an instant, and
|
||||
* {@link Span#instant}, otherwise.
|
||||
*/
|
||||
Span getSpan();
|
||||
|
||||
String asJson();
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.nosqlbench.nb.api.annotations;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import io.nosqlbench.nb.api.Layer;
|
||||
|
||||
import java.time.Instant;
|
||||
@ -9,13 +12,25 @@ import java.util.*;
|
||||
|
||||
public class MutableAnnotation implements Annotation {
|
||||
|
||||
private final static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
private String session = "SESSION_UNNAMED";
|
||||
|
||||
@Expose
|
||||
private Layer layer;
|
||||
|
||||
@Expose
|
||||
private long start = 0L;
|
||||
|
||||
@Expose
|
||||
private long end = 0L;
|
||||
|
||||
@Expose
|
||||
private Map<String, String> labels = new LinkedHashMap<>();
|
||||
|
||||
@Expose
|
||||
private Map<String, String> details = new LinkedHashMap<>();
|
||||
private ZoneId zoneid = ZoneId.of("GMT");
|
||||
|
||||
private final ZoneId zoneid = ZoneId.of("GMT");
|
||||
|
||||
public MutableAnnotation(
|
||||
TimeZone timezone,
|
||||
@ -25,24 +40,28 @@ public class MutableAnnotation implements Annotation {
|
||||
long end,
|
||||
LinkedHashMap<String, String> labels,
|
||||
LinkedHashMap<String, String> details) {
|
||||
this.session = session;
|
||||
this.layer = layer;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.details = details;
|
||||
this.labels = labels;
|
||||
setLabels(labels);
|
||||
setSession(session);
|
||||
setLayer(layer);
|
||||
setStart(start);
|
||||
setEnd(end);
|
||||
setDetails(details);
|
||||
labels.put("appname", "nosqlbench");
|
||||
}
|
||||
|
||||
public void setSession(String sessionName) {
|
||||
this.session = sessionName;
|
||||
this.labels.put("session", sessionName);
|
||||
}
|
||||
|
||||
public void setStart(long intervalStart) {
|
||||
this.start = intervalStart;
|
||||
this.labels.put("span", getSpan().toString());
|
||||
}
|
||||
|
||||
public void setEnd(long intervalEnd) {
|
||||
this.end = intervalEnd;
|
||||
this.labels.put("span", getSpan().toString());
|
||||
}
|
||||
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
@ -80,6 +99,9 @@ public class MutableAnnotation implements Annotation {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getLabels() {
|
||||
// if (!labels.containsKey("span")) {
|
||||
// labels.put("span",getSpan().toString());
|
||||
// }
|
||||
return labels;
|
||||
}
|
||||
|
||||
@ -102,6 +124,8 @@ public class MutableAnnotation implements Annotation {
|
||||
sb.append(" - ").append(endTime);
|
||||
}
|
||||
sb.append("]\n");
|
||||
|
||||
sb.append("span:").append(getSpan()).append("\n");
|
||||
sb.append("details:\n");
|
||||
formatMap(sb, getDetails());
|
||||
sb.append("labels:\n");
|
||||
@ -126,8 +150,16 @@ public class MutableAnnotation implements Annotation {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Annotation asReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Span getSpan() {
|
||||
return (getStart() == getEnd()) ? Span.instant : Span.interval;
|
||||
}
|
||||
|
||||
public String asJson() {
|
||||
String inlineForm = gson.toJson(this);
|
||||
return inlineForm;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user