Debian Codegraph @

includes/libs/Stats/Metrics/MetricInterface.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 * @file
18 */
19
20 namespace Wikimedia\Stats\Metrics;
21
22 use Psr\Log\LoggerInterface;
23 use Wikimedia\Stats\Sample;
24
25 /**
26 * Metric Interface
27 *
28 * @author Cole White
29 * @since 1.41
30 */
31 interface MetricInterface {
32 /**
33 * @param BaseMetricInterface $baseMetric
34 * @param LoggerInterface $logger
35 */
36 public function __construct( BaseMetricInterface $baseMetric, LoggerInterface $logger );
37
38 /** @return string */
39 public function getName(): string;
40
41 /** @return string */
42 public function getComponent(): string;
43
44 /** @return float */
45 public function getSampleRate(): float;
46
47 /** @return string */
48 public function getTypeIndicator(): string;
49
50 /**
51 * Returns subset of samples corresponding to sample rate setting.
52 *
53 * @return Sample[]
54 */
55 public function getSamples(): array;
56
57 /**
58 * Returns a count of samples recorded by the metric.
59 *
60 * @return int
61 */
62 public function getSampleCount(): int;
63
64 /**
65 * Sets sample rate on a new metric instance.
66 *
67 * @param float $sampleRate
68 * @return self|NullMetric
69 */
70 public function setSampleRate( float $sampleRate );
71
72 /**
73 * Returns the list of defined label keys.
74 *
75 * @return string[]
76 */
77 public function getLabelKeys(): array;
78
79 /**
80 * Adds a label $key with $value.
81 * Note that the order in which labels are added is significant for StatsD output.
82 *
83 * Example:
84 * ```php
85 * $statsFactory->getCounter( 'testMetric_total' )
86 * ->setLabel( 'first', 'foo' )
87 * ->setLabel( 'second', 'bar' )
88 * ->increment();
89 * ```
90 * statsd: "mediawiki.testMetric_total.foo.bar"
91 * prometheus: "mediawiki_testMetric_total{ first='foo', second='bar' }
92 *
93 * @param string $key
94 * @param string $value
95 * @return self|NullMetric
96 */
97 public function setLabel( string $key, string $value );
98
99 /**
100 * Convenience function to set a number of labels at once.
101 * @see ::setLabel
102 * @param array<string,string> $labels
103 * @return self|NullMetric
104 */
105 public function setLabels( array $labels );
106
107 /**
108 * Copies metric operation to StatsD at provided namespace.
109 *
110 * Takes a namespace or multiple namespaces.
111 *
112 * @param string|string[] $statsdNamespaces
113 * @return self|NullMetric
114 */
115 public function copyToStatsdAt( $statsdNamespaces );
116
117 /**
118 * Returns metric with cleared labels.
119 *
120 * @return self|NullMetric
121 */
122 public function fresh();
123 }