github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/metric/fake_metric.go (about) 1 // Copyright 2022 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package metric 16 17 import pb "github.com/nicocha30/gvisor-ligolo/pkg/metric/metric_go_proto" 18 19 // FakeUint64Metric is a type that implements all the methods of a Uint64Metric 20 // as a no-op. 21 type FakeUint64Metric struct{} 22 23 // FakeDistributionMetric is a type that implements all the methods of a 24 // DistributionMetric as a no-op. 25 type FakeDistributionMetric struct{} 26 27 // FakeTimerMetric is a type that implements all the methods of a TimerMetric 28 // as a no-op. 29 type FakeTimerMetric struct{} 30 31 // FakeTimedOperation is a type that implements all the methods of a 32 // TimedOperation as a no-op. 33 type FakeTimedOperation struct{} 34 35 // Value from a FakeUint64Metric always returns a meaningless value. 36 // 37 //go:nosplit 38 func (m *FakeUint64Metric) Value(fieldValues ...*FieldValue) uint64 { 39 return 0 40 } 41 42 // Increment on a FakeUint64Metric does nothing. 43 // 44 //go:nosplit 45 func (m *FakeUint64Metric) Increment(fieldValues ...*FieldValue) {} 46 47 // IncrementBy on a FakeUint64Metric does nothing. 48 // 49 //go:nosplit 50 func (m *FakeUint64Metric) IncrementBy(v uint64, fieldValues ...*FieldValue) {} 51 52 // AddSample on a FakeUint64Metric does nothing. 53 // 54 //go:nosplit 55 func (d *FakeDistributionMetric) AddSample(sample int64, fields ...*FieldValue) {} 56 57 // Start on a FakeUint64Metric returns a FakeTimedOperation struct, which does 58 // nothing and does not keep the time. 59 // 60 //go:nosplit 61 func (t *FakeTimerMetric) Start(fields ...*FieldValue) FakeTimedOperation { 62 return FakeTimedOperation{} 63 } 64 65 // Finish on a FakeTimedOperation does nothing. 66 // 67 //go:nosplit 68 func (o FakeTimedOperation) Finish(extraFields ...*FieldValue) {} 69 70 // NewFakeUint64Metric is equivalent to NewUint64Metric except it creates a 71 // FakeUint64Metric 72 func NewFakeUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string, fields ...Field) (*FakeUint64Metric, error) { 73 return &FakeUint64Metric{}, nil 74 } 75 76 // MustCreateNewFakeUint64Metric is equivalent to MustCreateNewUint64Metric 77 // except it creates a FakeUint64Metric. 78 func MustCreateNewFakeUint64Metric(name string, sync bool, description string, fields ...Field) *FakeUint64Metric { 79 return &FakeUint64Metric{} 80 } 81 82 // NewFakeDistributionMetric is equivalent to NewDistributionMetric except 83 // it creates a FakeDistributionMetric. 84 func NewFakeDistributionMetric(name string, sync bool, bucketer Bucketer, unit pb.MetricMetadata_Units, description string, fields ...Field) (*FakeDistributionMetric, error) { 85 return &FakeDistributionMetric{}, nil 86 } 87 88 // MustCreateNewFakeDistributionMetric is equivalent to 89 // MustCreateNewDistributionMetric except it creates a FakeDistributionMetric. 90 func MustCreateNewFakeDistributionMetric(name string, sync bool, bucketer Bucketer, unit pb.MetricMetadata_Units, description string, fields ...Field) *FakeDistributionMetric { 91 return &FakeDistributionMetric{} 92 } 93 94 // NewFakeTimerMetric is equivalent to NewTimerMetric except it creates a 95 // FakeTimerMetric. 96 func NewFakeTimerMetric(name string, nanoBucketer Bucketer, description string, fields ...Field) (*FakeTimerMetric, error) { 97 return &FakeTimerMetric{}, nil 98 } 99 100 // MustCreateNewFakeTimerMetric is equivalent to MustCreateNewTimerMetric 101 // except it creates a FakeTimerMetric. 102 func MustCreateNewFakeTimerMetric(name string, nanoBucketer Bucketer, description string, fields ...Field) *FakeTimerMetric { 103 return &FakeTimerMetric{} 104 }