aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/Metric.java
blob: 170dde55c19e9551608e0e256235b2ec70478631 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc;

import com.google.inject.ProvidedBy;
import com.google.inject.Provider;
import com.yahoo.jdisc.application.MetricConsumer;
import com.yahoo.jdisc.application.MetricProvider;

import java.util.Map;

/**
 * <p>This interface provides an API for writing metric data to the configured {@link MetricConsumer}. If no {@link
 * Provider} for the MetricConsumer class has been bound by the application, all calls to this interface are no-ops. The
 * implementation of this interface uses thread local consumer instances, so as long as the {@link MetricConsumer} is
 * thread-safe, so is this.</p>
 *
 * <p>An instance of this class can be injected anywhere.</p>
 *
 * @author Simon Thoresen Hult
 */
@ProvidedBy(MetricProvider.class)
public interface Metric {

    /**
     * Set a metric value. This is typically used with histogram-type metrics.
     *
     * @param key The name of the metric to modify.
     * @param val The value to assign to the named metric.
     * @param ctx The context to further describe this entry.
     */
    void set(String key, Number val, Context ctx);

    /**
     * Add to a metric value. This is typically used with counter-type metrics.
     *
     * @param key the name of the metric to modify
     * @param val the value to add to the named metric
     * @param ctx the context to further describe this entry
     */
    void add(String key, Number val, Context ctx);

    /**
     * Creates a {@link MetricConsumer}-specific {@link Context} object that encapsulates the given properties. The
     * returned Context object should be passed along every future call to {@link #set(String, Number, Context)} and
     * {@link #add(String, Number, Context)} where the properties match those given here.
     *
     * @param properties the properties to incorporate in the context
     * @return the created context
     */
    Context createContext(Map<String, ?> properties);

    /**
     * Declares the interface for the arbitrary context object to pass to both the {@link
     * #set(String, Number, Context)} and {@link #add(String, Number, Context)} methods. This is intentionally empty so
     * that implementations can vary.
     */
    interface Context {

    }

}