| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT. |
| 5 |
// To regenerate this file run "make genpdata". |
| 6 |
|
| 7 |
package pmetric |
| 8 |
|
| 9 |
import ( |
| 10 |
"go.opentelemetry.io/collector/pdata/internal" |
| 11 |
"go.opentelemetry.io/collector/pdata/pcommon" |
| 12 |
) |
| 13 |
|
| 14 |
// Metric represents one metric as a collection of datapoints. |
| 15 |
// See Metric definition in OTLP: https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto |
| 16 |
// |
| 17 |
// This is a reference type, if passed by value and callee modifies it the |
| 18 |
// caller will see the modification. |
| 19 |
// |
| 20 |
// Must use NewMetric function to create new instances. |
| 21 |
// Important: zero-initialized instance is not valid for use. |
| 22 |
type Metric struct { |
| 23 |
orig *internal.Metric |
| 24 |
state *internal.State |
| 25 |
} |
| 26 |
|
| 27 |
func newMetric(orig *internal.Metric, state *internal.State) Metric { |
| 28 |
return Metric{orig: orig, state: state} |
| 29 |
} |
| 30 |
|
| 31 |
// NewMetric creates a new empty Metric. |
| 32 |
// |
| 33 |
// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, |
| 34 |
// OR directly access the member if this is embedded in another struct. |
| 35 |
func NewMetric() Metric { |
| 36 |
return newMetric(internal.NewMetric(), internal.NewState()) |
| 37 |
} |
| 38 |
|
| 39 |
// MoveTo moves all properties from the current struct overriding the destination and |
| 40 |
// resetting the current instance to its zero value |
| 41 |
func (ms Metric) MoveTo(dest Metric) { |
| 42 |
ms.state.AssertMutable() |
| 43 |
dest.state.AssertMutable() |
| 44 |
// If they point to the same data, they are the same, nothing to do. |
| 45 |
if ms.orig == dest.orig { |
| 46 |
return |
| 47 |
} |
| 48 |
internal.DeleteMetric(dest.orig, false) |
| 49 |
*dest.orig, *ms.orig = *ms.orig, *dest.orig |
| 50 |
} |
| 51 |
|
| 52 |
// Name returns the name associated with this Metric. |
| 53 |
func (ms Metric) Name() string { |
| 54 |
return ms.orig.Name |
| 55 |
} |
| 56 |
|
| 57 |
// SetName replaces the name associated with this Metric. |
| 58 |
func (ms Metric) SetName(v string) { |
| 59 |
ms.state.AssertMutable() |
| 60 |
ms.orig.Name = v |
| 61 |
} |
| 62 |
|
| 63 |
// Description returns the description associated with this Metric. |
| 64 |
func (ms Metric) Description() string { |
| 65 |
return ms.orig.Description |
| 66 |
} |
| 67 |
|
| 68 |
// SetDescription replaces the description associated with this Metric. |
| 69 |
func (ms Metric) SetDescription(v string) { |
| 70 |
ms.state.AssertMutable() |
| 71 |
ms.orig.Description = v |
| 72 |
} |
| 73 |
|
| 74 |
// Unit returns the unit associated with this Metric. |
| 75 |
func (ms Metric) Unit() string { |
| 76 |
return ms.orig.Unit |
| 77 |
} |
| 78 |
|
| 79 |
// SetUnit replaces the unit associated with this Metric. |
| 80 |
func (ms Metric) SetUnit(v string) { |
| 81 |
ms.state.AssertMutable() |
| 82 |
ms.orig.Unit = v |
| 83 |
} |
| 84 |
|
| 85 |
// Type returns the type of the data for this Metric. |
| 86 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 87 |
func (ms Metric) Type() MetricType { |
| 88 |
switch ms.orig.Data.(type) { |
| 89 |
case *internal.Metric_Gauge: |
| 90 |
return MetricTypeGauge |
| 91 |
case *internal.Metric_Sum: |
| 92 |
return MetricTypeSum |
| 93 |
case *internal.Metric_Histogram: |
| 94 |
return MetricTypeHistogram |
| 95 |
case *internal.Metric_ExponentialHistogram: |
| 96 |
return MetricTypeExponentialHistogram |
| 97 |
case *internal.Metric_Summary: |
| 98 |
return MetricTypeSummary |
| 99 |
} |
| 100 |
return MetricTypeEmpty |
| 101 |
} |
| 102 |
|
| 103 |
// Gauge returns the gauge associated with this Metric. |
| 104 |
// |
| 105 |
// Calling this function when Type() != MetricTypeGauge returns an invalid |
| 106 |
// zero-initialized instance of Gauge. Note that using such Gauge instance can cause panic. |
| 107 |
// |
| 108 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 109 |
func (ms Metric) Gauge() Gauge { |
| 110 |
v, ok := ms.orig.GetData().(*internal.Metric_Gauge) |
| 111 |
if !ok { |
| 112 |
return Gauge{} |
| 113 |
} |
| 114 |
return newGauge(v.Gauge, ms.state) |
| 115 |
} |
| 116 |
|
| 117 |
// SetEmptyGauge sets an empty gauge to this Metric. |
| 118 |
// |
| 119 |
// After this, Type() function will return MetricTypeGauge". |
| 120 |
// |
| 121 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 122 |
func (ms Metric) SetEmptyGauge() Gauge { |
| 123 |
ms.state.AssertMutable() |
| 124 |
var ov *internal.Metric_Gauge |
| 125 |
if !internal.UseProtoPooling.IsEnabled() { |
| 126 |
ov = &internal.Metric_Gauge{} |
| 127 |
} else { |
| 128 |
ov = internal.ProtoPoolMetric_Gauge.Get().(*internal.Metric_Gauge) |
| 129 |
} |
| 130 |
ov.Gauge = internal.NewGauge() |
| 131 |
ms.orig.Data = ov |
| 132 |
return newGauge(ov.Gauge, ms.state) |
| 133 |
} |
| 134 |
|
| 135 |
// Sum returns the sum associated with this Metric. |
| 136 |
// |
| 137 |
// Calling this function when Type() != MetricTypeSum returns an invalid |
| 138 |
// zero-initialized instance of Sum. Note that using such Sum instance can cause panic. |
| 139 |
// |
| 140 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 141 |
func (ms Metric) Sum() Sum { |
| 142 |
v, ok := ms.orig.GetData().(*internal.Metric_Sum) |
| 143 |
if !ok { |
| 144 |
return Sum{} |
| 145 |
} |
| 146 |
return newSum(v.Sum, ms.state) |
| 147 |
} |
| 148 |
|
| 149 |
// SetEmptySum sets an empty sum to this Metric. |
| 150 |
// |
| 151 |
// After this, Type() function will return MetricTypeSum". |
| 152 |
// |
| 153 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 154 |
func (ms Metric) SetEmptySum() Sum { |
| 155 |
ms.state.AssertMutable() |
| 156 |
var ov *internal.Metric_Sum |
| 157 |
if !internal.UseProtoPooling.IsEnabled() { |
| 158 |
ov = &internal.Metric_Sum{} |
| 159 |
} else { |
| 160 |
ov = internal.ProtoPoolMetric_Sum.Get().(*internal.Metric_Sum) |
| 161 |
} |
| 162 |
ov.Sum = internal.NewSum() |
| 163 |
ms.orig.Data = ov |
| 164 |
return newSum(ov.Sum, ms.state) |
| 165 |
} |
| 166 |
|
| 167 |
// Histogram returns the histogram associated with this Metric. |
| 168 |
// |
| 169 |
// Calling this function when Type() != MetricTypeHistogram returns an invalid |
| 170 |
// zero-initialized instance of Histogram. Note that using such Histogram instance can cause panic. |
| 171 |
// |
| 172 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 173 |
func (ms Metric) Histogram() Histogram { |
| 174 |
v, ok := ms.orig.GetData().(*internal.Metric_Histogram) |
| 175 |
if !ok { |
| 176 |
return Histogram{} |
| 177 |
} |
| 178 |
return newHistogram(v.Histogram, ms.state) |
| 179 |
} |
| 180 |
|
| 181 |
// SetEmptyHistogram sets an empty histogram to this Metric. |
| 182 |
// |
| 183 |
// After this, Type() function will return MetricTypeHistogram". |
| 184 |
// |
| 185 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 186 |
func (ms Metric) SetEmptyHistogram() Histogram { |
| 187 |
ms.state.AssertMutable() |
| 188 |
var ov *internal.Metric_Histogram |
| 189 |
if !internal.UseProtoPooling.IsEnabled() { |
| 190 |
ov = &internal.Metric_Histogram{} |
| 191 |
} else { |
| 192 |
ov = internal.ProtoPoolMetric_Histogram.Get().(*internal.Metric_Histogram) |
| 193 |
} |
| 194 |
ov.Histogram = internal.NewHistogram() |
| 195 |
ms.orig.Data = ov |
| 196 |
return newHistogram(ov.Histogram, ms.state) |
| 197 |
} |
| 198 |
|
| 199 |
// ExponentialHistogram returns the exponentialhistogram associated with this Metric. |
| 200 |
// |
| 201 |
// Calling this function when Type() != MetricTypeExponentialHistogram returns an invalid |
| 202 |
// zero-initialized instance of ExponentialHistogram. Note that using such ExponentialHistogram instance can cause panic. |
| 203 |
// |
| 204 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 205 |
func (ms Metric) ExponentialHistogram() ExponentialHistogram { |
| 206 |
v, ok := ms.orig.GetData().(*internal.Metric_ExponentialHistogram) |
| 207 |
if !ok { |
| 208 |
return ExponentialHistogram{} |
| 209 |
} |
| 210 |
return newExponentialHistogram(v.ExponentialHistogram, ms.state) |
| 211 |
} |
| 212 |
|
| 213 |
// SetEmptyExponentialHistogram sets an empty exponentialhistogram to this Metric. |
| 214 |
// |
| 215 |
// After this, Type() function will return MetricTypeExponentialHistogram". |
| 216 |
// |
| 217 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 218 |
func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { |
| 219 |
ms.state.AssertMutable() |
| 220 |
var ov *internal.Metric_ExponentialHistogram |
| 221 |
if !internal.UseProtoPooling.IsEnabled() { |
| 222 |
ov = &internal.Metric_ExponentialHistogram{} |
| 223 |
} else { |
| 224 |
ov = internal.ProtoPoolMetric_ExponentialHistogram.Get().(*internal.Metric_ExponentialHistogram) |
| 225 |
} |
| 226 |
ov.ExponentialHistogram = internal.NewExponentialHistogram() |
| 227 |
ms.orig.Data = ov |
| 228 |
return newExponentialHistogram(ov.ExponentialHistogram, ms.state) |
| 229 |
} |
| 230 |
|
| 231 |
// Summary returns the summary associated with this Metric. |
| 232 |
// |
| 233 |
// Calling this function when Type() != MetricTypeSummary returns an invalid |
| 234 |
// zero-initialized instance of Summary. Note that using such Summary instance can cause panic. |
| 235 |
// |
| 236 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 237 |
func (ms Metric) Summary() Summary { |
| 238 |
v, ok := ms.orig.GetData().(*internal.Metric_Summary) |
| 239 |
if !ok { |
| 240 |
return Summary{} |
| 241 |
} |
| 242 |
return newSummary(v.Summary, ms.state) |
| 243 |
} |
| 244 |
|
| 245 |
// SetEmptySummary sets an empty summary to this Metric. |
| 246 |
// |
| 247 |
// After this, Type() function will return MetricTypeSummary". |
| 248 |
// |
| 249 |
// Calling this function on zero-initialized Metric will cause a panic. |
| 250 |
func (ms Metric) SetEmptySummary() Summary { |
| 251 |
ms.state.AssertMutable() |
| 252 |
var ov *internal.Metric_Summary |
| 253 |
if !internal.UseProtoPooling.IsEnabled() { |
| 254 |
ov = &internal.Metric_Summary{} |
| 255 |
} else { |
| 256 |
ov = internal.ProtoPoolMetric_Summary.Get().(*internal.Metric_Summary) |
| 257 |
} |
| 258 |
ov.Summary = internal.NewSummary() |
| 259 |
ms.orig.Data = ov |
| 260 |
return newSummary(ov.Summary, ms.state) |
| 261 |
} |
| 262 |
|
| 263 |
// Metadata returns the Metadata associated with this Metric. |
| 264 |
func (ms Metric) Metadata() pcommon.Map { |
| 265 |
return pcommon.Map(internal.NewMapWrapper(&ms.orig.Metadata, ms.state)) |
| 266 |
} |
| 267 |
|
| 268 |
// CopyTo copies all properties from the current struct overriding the destination. |
| 269 |
func (ms Metric) CopyTo(dest Metric) { |
| 270 |
dest.state.AssertMutable() |
| 271 |
internal.CopyMetric(dest.orig, ms.orig) |
| 272 |
} |