Update git submodules
[mediawiki.git] / includes / libs / Stats / Metrics / MetricInterface.php
blob01a772998fd3d55963c90d487dbb58325a6a0657
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.
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.
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
20 namespace Wikimedia\Stats\Metrics;
22 use Psr\Log\LoggerInterface;
23 use Wikimedia\Stats\Sample;
25 /**
26 * Metric Interface
28 * @author Cole White
29 * @since 1.41
31 interface MetricInterface {
32 /**
33 * @param BaseMetricInterface $baseMetric
34 * @param LoggerInterface $logger
36 public function __construct( BaseMetricInterface $baseMetric, LoggerInterface $logger );
38 /** @return string */
39 public function getName(): string;
41 /** @return string */
42 public function getComponent(): string;
44 /** @return float */
45 public function getSampleRate(): float;
47 /** @return string */
48 public function getTypeIndicator(): string;
50 /**
51 * Returns subset of samples corresponding to sample rate setting.
53 * @return Sample[]
55 public function getSamples(): array;
57 /**
58 * Sets sample rate on a new metric instance.
60 * @param float $sampleRate
61 * @return CounterMetric|GaugeMetric|TimingMetric|NullMetric
63 public function setSampleRate( float $sampleRate );
65 /**
66 * Returns the list of defined label keys.
68 * @return string[]
70 public function getLabelKeys(): array;
72 /**
73 * Adds a label $key with $value.
75 * @param string $key
76 * @param string $value
77 * @return CounterMetric|GaugeMetric|TimingMetric|NullMetric
79 public function setLabel( string $key, string $value );
81 /**
82 * Copies metric operation to StatsD at provided namespace.
84 * @param string $statsdNamespace
85 * @return CounterMetric|GaugeMetric|TimingMetric|NullMetric
87 public function copyToStatsdAt( string $statsdNamespace );
89 /**
90 * Returns metric with cleared labels.
92 * @return CounterMetric|GaugeMetric|TimingMetric|NullMetric
94 public function fresh();