@@ -23,7 +23,6 @@ import (
23
23
24
24
dto "github.com/prometheus/client_model/go"
25
25
"google.golang.org/protobuf/encoding/protodelim"
26
- "google.golang.org/protobuf/encoding/prototext"
27
26
28
27
"github.com/prometheus/common/model"
29
28
)
@@ -76,11 +75,8 @@ func ResponseFormat(h http.Header) Format {
76
75
// This decoder does not fully support OpenMetrics although it may often succeed
77
76
// due to the similarities between the formats. This decoder may not support the
78
77
// latest features of Prometheus text format and is not intended for
79
- // high-performance applications. The parsers in Prometheus
80
- // (https://github.com/prometheus/prometheus/blob/main/model/textparse/promparse.go
81
- // and
82
- // https://github.com/prometheus/prometheus/blob/main/model/textparse/openmetricsparse.go)
83
- // are more regularly maintained.
78
+ // high-performance applications. See:
79
+ // https://github.com/prometheus/common/issues/812
84
80
func NewDecoder (r io.Reader , format Format ) Decoder {
85
81
scheme := model .LegacyValidation
86
82
if format .ToEscapingScheme () == model .NoEscaping {
@@ -90,7 +86,7 @@ func NewDecoder(r io.Reader, format Format) Decoder {
90
86
case TypeProtoDelim :
91
87
return & protoDecoder {r : bufio .NewReader (r ), s : scheme }
92
88
case TypeProtoText , TypeProtoCompact :
93
- return & prototextDecoder { r : r , s : scheme }
89
+ return & errDecoder { err : fmt . Errorf ( "format %s not supported for decoding" , format ) }
94
90
}
95
91
return & textDecoder {r : r , s : scheme }
96
92
}
@@ -131,43 +127,13 @@ func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
131
127
return nil
132
128
}
133
129
134
- // prototextDecoder implements the Decoder interface for protocol buffers that
135
- // are encoded in text format.
136
- type prototextDecoder struct {
137
- r io.Reader
138
- s model.ValidationScheme
130
+ // errDecoder is an error-state decoder that always returns the same error.
131
+ type errDecoder struct {
132
+ err error
139
133
}
140
134
141
- // Decode implements the Decoder interface.
142
- func (d * prototextDecoder ) Decode (v * dto.MetricFamily ) error {
143
- opts := prototext.UnmarshalOptions {}
144
- b , err := io .ReadAll (d .r )
145
- if err != nil {
146
- return err
147
- }
148
- if err := opts .Unmarshal (b , 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
135
+ func (d * errDecoder ) Decode (v * dto.MetricFamily ) error {
136
+ return d .err
171
137
}
172
138
173
139
// textDecoder implements the Decoder interface for the text protocol.
0 commit comments