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

Function NewDecoder

expfmt/decode.go:85–102  ·  view source on GitHub ↗

NewDecoder returns a new decoder based on the given input format. Metric names are validated based on the provided Format -- if the format requires escaping, traditional Prometheus validity checking is used. Otherwise, names are checked for UTF-8 validity. Supported formats include delimited protobu

(r io.Reader, format Format)

Source from the content-addressed store, hash-verified

83// applications.
84// See: https://github.com/prometheus/common/issues/812
85func NewDecoder(r io.Reader, format Format) Decoder {
86 scheme := model.LegacyValidation
87 if format.ToEscapingScheme() == model.NoEscaping {
88 scheme = model.UTF8Validation
89 }
90 switch format.FormatType() {
91 case TypeProtoDelim:
92 return &protoDecoder{r: bufio.NewReader(r), s: scheme}
93 case TypeProtoText, TypeProtoCompact:
94 return &errDecoder{err: fmt.Errorf("format %s not supported for decoding", format)}
95 case TypeOpenMetrics:
96 _, params, err := mime.ParseMediaType(string(format))
97 if err == nil && params["version"] == OpenMetricsVersion_2_0_0 {
98 return &errDecoder{err: fmt.Errorf("format %s not supported for decoding", format)}
99 }
100 }
101 return &textDecoder{r: r, s: scheme}
102}
103
104// protoDecoder implements the Decoder interface for protocol buffers.
105type protoDecoder struct {

Callers 4

TestNewDecoderFunction · 0.85
TestDottedEncodeFunction · 0.85

Calls 2

ToEscapingSchemeMethod · 0.80
FormatTypeMethod · 0.80

Tested by 4

TestNewDecoderFunction · 0.68
TestDottedEncodeFunction · 0.68