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

Method Decode

expfmt/decode.go:89–116  ·  view source on GitHub ↗

Decode implements the Decoder interface.

(v *dto.MetricFamily)

Source from the content-addressed store, hash-verified

87
88// Decode implements the Decoder interface.
89func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
90 opts := protodelim.UnmarshalOptions{
91 MaxSize: -1,
92 }
93 if err := opts.UnmarshalFrom(bufio.NewReader(d.r), v); err != nil {
94 return err
95 }
96 if !model.IsValidMetricName(model.LabelValue(v.GetName())) {
97 return fmt.Errorf("invalid metric name %q", v.GetName())
98 }
99 for _, m := range v.GetMetric() {
100 if m == nil {
101 continue
102 }
103 for _, l := range m.GetLabel() {
104 if l == nil {
105 continue
106 }
107 if !model.LabelValue(l.GetValue()).IsValid() {
108 return fmt.Errorf("invalid label value %q", l.GetValue())
109 }
110 if !model.LabelName(l.GetName()).IsValid() {
111 return fmt.Errorf("invalid label name %q", l.GetName())
112 }
113 }
114 }
115 return nil
116}
117
118// textDecoder implements the Decoder interface for the text protocol.
119type textDecoder struct {

Callers

nothing calls this directly

Calls 4

IsValidMetricNameFunction · 0.92
LabelValueTypeAlias · 0.92
LabelNameTypeAlias · 0.92
IsValidMethod · 0.45

Tested by

no test coverage detected