summaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/Metric.java
blob: 7a7cbcb071b34340bf41979c5bba407d6c578351 (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 2016 Yahoo Inc. 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
 */
@ProvidedBy(MetricProvider.class)
public interface Metric {

    /**
     * <p>Set a metric value. This is typically used with histogram-type metrics.</p>
     *
     * @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);

    /**
     * <p>Add to a metric value. This is typically used with counter-type metrics.</p>
     *
     * @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);

    /**
     * <p>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.</p>
     *
     * @param properties The properties to incorporate in the context.
     * @return The created context.
     */
    Context createContext(Map<String, ?> properties);

    /**
     * <p>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.</p>
     */
    interface Context {

    }

}