MCPcopy Create free account
hub / github.com/prometheus/common / Decode

Method Decode

expfmt/decode.go:144–171  ·  view source on GitHub ↗

Decode implements the Decoder interface.

(v *dto.MetricFamily)

Source from the content-addressed store, hash-verified

142
143// Decode implements the Decoder interface.
144func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
145 opts := protodelim.UnmarshalOptions{
146 MaxSize: -1,
147 }
148 if err := opts.UnmarshalFrom(d.r, v); err != nil {
149 return err
150 }
151 if !d.s.IsValidMetricName(v.GetName()) {
152 return fmt.Errorf("invalid metric name %q", v.GetName())
153 }
154 for _, m := range v.GetMetric() {
155 if m == nil {
156 continue
157 }
158 for _, l := range m.GetLabel() {
159 if l == nil {
160 continue
161 }
162 if !model.LabelValue(l.GetValue()).IsValid() {
163 return fmt.Errorf("invalid label value %q", l.GetValue())
164 }
165 if !d.s.IsValidLabelName(l.GetName()) {
166 return fmt.Errorf("invalid label name %q", l.GetName())
167 }
168 }
169 }
170 return nil
171}
172
173// errDecoder is an error-state decoder that always returns the same error.
174type errDecoder struct {

Callers

nothing calls this directly

Calls 4

LabelValueTypeAlias · 0.92
IsValidMetricNameMethod · 0.80
IsValidLabelNameMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected