|
|
|
@ -1,8 +1,11 @@ |
|
|
|
|
package marshal |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"fmt" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"unicode/utf8" |
|
|
|
|
"unsafe" |
|
|
|
|
|
|
|
|
|
jsoniter "github.com/json-iterator/go" |
|
|
|
@ -20,6 +23,16 @@ import ( |
|
|
|
|
"github.com/grafana/loki/v3/pkg/util/httpreq" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
// The rune error replacement is rejected by Prometheus hence replacing them with space.
|
|
|
|
|
removeInvalidUtf = func(r rune) rune { |
|
|
|
|
if r == utf8.RuneError { |
|
|
|
|
return 32 // rune value for space
|
|
|
|
|
} |
|
|
|
|
return r |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// NewResultValue constructs a ResultValue from a promql.Value
|
|
|
|
|
func NewResultValue(v parser.Value) (loghttp.ResultValue, error) { |
|
|
|
|
var err error |
|
|
|
@ -77,6 +90,9 @@ func NewStreams(s logqlmodel.Streams) (loghttp.Streams, error) { |
|
|
|
|
ret := make([]loghttp.Stream, len(s)) |
|
|
|
|
|
|
|
|
|
for i, stream := range s { |
|
|
|
|
if strings.ContainsRune(stream.Labels, utf8.RuneError) { |
|
|
|
|
stream.Labels = string(bytes.Map(removeInvalidUtf, []byte(stream.Labels))) |
|
|
|
|
} |
|
|
|
|
ret[i], err = NewStream(stream) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|