Search in sources :

Example 1 with Point

use of com.yahoo.metrics.simple.Point in project vespa by vespa-engine.

the class SnapshotConverter method convert.

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);
}
Also used : Value(com.yahoo.metrics.simple.Value) Point(com.yahoo.metrics.simple.Point)

Example 2 with Point

use of com.yahoo.metrics.simple.Point in project vespa by vespa-engine.

the class SnapshotConverter method getIdentifierString.

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();
}
Also used : Value(com.yahoo.metrics.simple.Value) Point(com.yahoo.metrics.simple.Point)

Example 3 with Point

use of com.yahoo.metrics.simple.Point in project vespa by vespa-engine.

the class SnapshotConverter method convert.

MetricSnapshot convert() {
    for (Map.Entry<Identifier, UntypedMetric> entry : snapshot.entrySet()) {
        Identifier ident = entry.getKey();
        getMap(ident.getLocation()).put(ident.getName(), convert(entry.getValue()));
    }
    Map<MetricDimensions, MetricSet> data = new HashMap<>();
    for (Map.Entry<Point, Map<String, MetricValue>> entry : perPointData.entrySet()) {
        MetricDimensions key = convert(entry.getKey());
        MetricSet newval = new MetricSet(entry.getValue());
        MetricSet old = data.get(key);
        if (old != null) {
            // should not happen, this is bad
            // TODO: consider merging the two MetricSet instances
            log.warning("losing MetricSet when converting for: " + entry.getKey());
        } else {
            data.put(key, newval);
        }
    }
    return new MetricSnapshot(snapshot.getFromMillis(), snapshot.getToMillis(), TimeUnit.MILLISECONDS, data);
}
Also used : Identifier(com.yahoo.metrics.simple.Identifier) Point(com.yahoo.metrics.simple.Point) UntypedMetric(com.yahoo.metrics.simple.UntypedMetric)

Example 4 with Point

use of com.yahoo.metrics.simple.Point in project vespa by vespa-engine.

the class SnapshotConverterTest method testConversion.

@Test
public void testConversion() {
    MetricReceiver mock = new MetricReceiver.MockReceiver();
    mock.declareCounter("foo").add(1);
    mock.declareGauge("quuux").sample(42.25);
    mock.declareCounter("bar", new Point(new HashMap<String, String>())).add(4);
    MetricSnapshot snapshot = new SnapshotConverter(mock.getSnapshot()).convert();
    for (Map.Entry<MetricDimensions, MetricSet> entry : snapshot) {
        for (Map.Entry<String, String> dv : entry.getKey()) {
            assertTrue(false);
        }
        int cnt = 0;
        for (Map.Entry<String, MetricValue> mv : entry.getValue()) {
            ++cnt;
            if ("foo".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof CountMetric);
                assertEquals(1, ((CountMetric) mv.getValue()).getCount());
            } else if ("bar".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof CountMetric);
                assertEquals(4, ((CountMetric) mv.getValue()).getCount());
            } else if ("quuux".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof GaugeMetric);
                assertEquals(42.25, ((GaugeMetric) mv.getValue()).getLast(), 0.001);
                assertEquals(1, ((GaugeMetric) mv.getValue()).getCount());
            } else {
                assertTrue(false);
            }
        }
        assertEquals(3, cnt);
    }
}
Also used : MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) MetricDimensions(com.yahoo.container.jdisc.state.MetricDimensions) CountMetric(com.yahoo.container.jdisc.state.CountMetric) GaugeMetric(com.yahoo.container.jdisc.state.GaugeMetric) Point(com.yahoo.metrics.simple.Point) Point(com.yahoo.metrics.simple.Point) MetricSet(com.yahoo.container.jdisc.state.MetricSet) MetricValue(com.yahoo.container.jdisc.state.MetricValue) MetricSnapshot(com.yahoo.container.jdisc.state.MetricSnapshot) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Point

use of com.yahoo.metrics.simple.Point in project vespa by vespa-engine.

the class DocumentApiMetrics method reportFailure.

public void reportFailure(DocumentOperationType documentOperationType, DocumentOperationStatus documentOperationStatus) {
    Point point = points.get(documentOperationStatus).get(documentOperationType);
    feeds.add(point);
}
Also used : Point(com.yahoo.metrics.simple.Point)

Aggregations

Point (com.yahoo.metrics.simple.Point)9 UntypedMetric (com.yahoo.metrics.simple.UntypedMetric)3 Test (org.junit.Test)3 MetricDimensions (com.yahoo.container.jdisc.state.MetricDimensions)2 MetricReceiver (com.yahoo.metrics.simple.MetricReceiver)2 Value (com.yahoo.metrics.simple.Value)2 HashMap (java.util.HashMap)2 ClusterInfoConfig (com.yahoo.cloud.config.ClusterInfoConfig)1 Chain (com.yahoo.component.chain.Chain)1 CountMetric (com.yahoo.container.jdisc.state.CountMetric)1 GaugeMetric (com.yahoo.container.jdisc.state.GaugeMetric)1 MetricSet (com.yahoo.container.jdisc.state.MetricSet)1 MetricSnapshot (com.yahoo.container.jdisc.state.MetricSnapshot)1 MetricValue (com.yahoo.container.jdisc.state.MetricValue)1 Identifier (com.yahoo.metrics.simple.Identifier)1 Searcher (com.yahoo.search.Searcher)1 RateLimitingConfig (com.yahoo.search.config.RateLimitingConfig)1 RateLimitingSearcher (com.yahoo.search.searchers.RateLimitingSearcher)1 ManualClock (com.yahoo.test.ManualClock)1 Map (java.util.Map)1