@Override public Context createContext(Map<String, ?> properties) { if (properties == null) properties = new HashMap<>(); return new Point(properties); }
public Point(Map<String, ?> properties) { this(buildParameters(properties)); }
/** * Create a new Point instance using the settings stored in this * PointBuilder. PointBuilder instances cannot be re-used after build() has * been invoked. * * @return a Point instance reflecting this builder */ public Point build() { Point p = Point.emptyPoint(); int size = dimensions.size(); if (size != 0) { p = new Point(dimensions.toArray(new String[size]), location.toArray(new Value[size])); } // deny builder re-use dimensions = null; location = null; return p; }
PointBuilder(Point p) { dimensions = new ArrayList<>(); location = new ArrayList<>(); if (p != null) { int size = p.dimensionality(); dimensions = new ArrayList<>(size+2); location = new ArrayList<>(size+2); for (String dimensionName : p.getDimensions()) { dimensions.add(dimensionName); } for (Value dimensionValue : p.getLocation()) { location.add(dimensionValue); } } else { dimensions = new ArrayList<>(4); location = new ArrayList<>(4); } }
static MetricDimensions convert(Point p) { if (p == null) { return StateMetricContext.newInstance(null); } List<String> dimensions = p.dimensions(); List<Value> location = p.location(); Map<String, Object> pointWrapper = new HashMap<>(dimensions.size()); for (int i = 0; i < dimensions.size(); ++i) { pointWrapper.put(dimensions.get(i), valueAsString(location.get(i))); } return StateMetricContext.newInstance(pointWrapper); }
public Identifier(String name, Point location) { this.name = (name == null ? "" : name); this.location = (location == null ? Point.emptyPoint() : location); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + location.hashCode(); result = prime * result + name.hashCode(); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Identifier other = (Identifier) obj; if (!location.equals(other.location)) { return false; } if (!name.equals(other.name)) { return false; } return true; }
private String getIdentifierString(Identifier id) { StringBuilder buffer = new StringBuilder(); Point location = id.getLocation(); buffer.append(id.getName()); if (location != null) { buffer.append(", dimensions: { "); Iterator<String> dimensions = location.dimensions().iterator(); Iterator<Value> values = location.location().iterator(); boolean firstDimension = true; while (dimensions.hasNext() && values.hasNext()) { if (firstDimension) { firstDimension = false; } else { buffer.append(", "); } serializeSingleDimension(buffer, dimensions.next(), values.next()); } buffer.append(" }"); } return buffer.toString(); }
private Map<String, MetricValue> getMap(Point point) { if (point == null) { point = Point.emptyPoint(); } if (! perPointData.containsKey(point)) { perPointData.put(point, new HashMap<>()); } return perPointData.get(point); }
public GaugeWrapper declareGauge(String application, Dimensions dimensions, String name, DimensionType type) { synchronized (monitor) { Map<Dimensions, Map<String, MetricValue>> metricsByDimensions = getOrCreateApplicationMetrics(application, type); if (!metricsByDimensions.containsKey(dimensions)) metricsByDimensions.put(dimensions, new HashMap<>()); if (!metricsByDimensions.get(dimensions).containsKey(name)) { GaugeWrapper gauge = new GaugeWrapper(metricReceiver.declareGauge(name, new Point(dimensions.dimensionsMap))); metricsByDimensions.get(dimensions).put(name, gauge); } return (GaugeWrapper) metricsByDimensions.get(dimensions).get(name); } }
public CounterWrapper declareCounter(String application, Dimensions dimensions, String name, DimensionType type) { synchronized (monitor) { Map<Dimensions, Map<String, MetricValue>> metricsByDimensions = getOrCreateApplicationMetrics(application, type); if (!metricsByDimensions.containsKey(dimensions)) metricsByDimensions.put(dimensions, new HashMap<>()); if (!metricsByDimensions.get(dimensions).containsKey(name)) { CounterWrapper counter = new CounterWrapper(metricReceiver.declareCounter(name, new Point(dimensions.dimensionsMap))); metricsByDimensions.get(dimensions).put(name, counter); } return (CounterWrapper) metricsByDimensions.get(dimensions).get(name); } }
public void reportHttpRequest(String clientVersion) { if (clientVersion != null) { try { Point point = versionPointCache.get(clientVersion, () -> new Point(Map.of("client-version", clientVersion))); feedRequests.add(point); } catch (ExecutionException e) { // When Point constructor throws an exception throw new RuntimeException(e); } } else { feedRequests.add(); } }
public DocumentApiMetrics(MetricReceiver metricReceiver, String apiName) { Map<String, String> dimensions = new HashMap<>(); dimensions.put("api", apiName); for (DocumentOperationStatus status : DocumentOperationStatus.values()) { points.put(status, new HashMap<>()); dimensions.put("status", status.name()); for (DocumentOperationType operation : DocumentOperationType.values()) { dimensions.put("operation", operation.name()); points.get(status).put(operation, new Point(dimensions)); } } feeds = metricReceiver.declareCounter("feed.operations"); feedLatency = metricReceiver.declareGauge("feed.latency"); feedRequests = metricReceiver.declareCounter("feed.http-requests"); }