mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
f548adce0b
- Parse protobuf if Content-Type isn't set to `application/json` - this behavior is documented at https://grafana.com/docs/loki/latest/api/#push-log-entries-to-loki - Properly handle gzip'ped JSON requests. The `gzip` header must be read from `Content-Encoding` instead of `Content-Type` header - Properly flush all the parsed logs with the explicit call to vlstorage.MustAddRows() at the end of query handler - Check JSON field types more strictly. - Allow parsing Loki timestamp as floating-point number. Such a timestamp can be generated by some clients, which store timestamps in float64 instead of int64. - Optimize parsing of Loki labels in Prometheus text exposition format. - Simplify tests. - Remove lib/slicesutil, since there are no more users for it. - Update docs with missing info and fix various typos. For example, it should be enough to have `instance` and `job` labels as stream fields in most Loki setups. - Allow empty of missing timestamps in the ingested logs. The current timestamp at VictoriaLogs side is then used for the ingested logs. This simplifies debugging and testing of the provided HTTP-based data ingestion APIs. The remaining MAJOR issue, which needs to be addressed: victoria-logs binary size increased from 13MB to 22MB after adding support for Loki data ingestion protocol at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4482 . This is because of shitty protobuf dependencies. They must be replaced with another protobuf implementation similar to the one used at lib/prompb or lib/prompbmarshal .
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package loki
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logstorage"
|
|
)
|
|
|
|
func BenchmarkParseJSONRequest(b *testing.B) {
|
|
for _, streams := range []int{5, 10} {
|
|
for _, rows := range []int{100, 1000} {
|
|
for _, labels := range []int{10, 50} {
|
|
b.Run(fmt.Sprintf("streams_%d/rows_%d/labels_%d", streams, rows, labels), func(b *testing.B) {
|
|
benchmarkParseJSONRequest(b, streams, rows, labels)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func benchmarkParseJSONRequest(b *testing.B, streams, rows, labels int) {
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(streams * rows))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
data := getJSONBody(streams, rows, labels)
|
|
for pb.Next() {
|
|
_, err := parseJSONRequest(data, func(timestamp int64, fields []logstorage.Field) {})
|
|
if err != nil {
|
|
panic(fmt.Errorf("unexpected error: %s", err))
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func getJSONBody(streams, rows, labels int) []byte {
|
|
body := append([]byte{}, `{"streams":[`...)
|
|
now := time.Now().UnixNano()
|
|
valuePrefix := fmt.Sprintf(`["%d","value_`, now)
|
|
|
|
for i := 0; i < streams; i++ {
|
|
body = append(body, `{"stream":{`...)
|
|
|
|
for j := 0; j < labels; j++ {
|
|
body = append(body, `"label_`...)
|
|
body = strconv.AppendInt(body, int64(j), 10)
|
|
body = append(body, `":"value_`...)
|
|
body = strconv.AppendInt(body, int64(j), 10)
|
|
body = append(body, '"')
|
|
if j < labels-1 {
|
|
body = append(body, ',')
|
|
}
|
|
|
|
}
|
|
body = append(body, `}, "values":[`...)
|
|
|
|
for j := 0; j < rows; j++ {
|
|
body = append(body, valuePrefix...)
|
|
body = strconv.AppendInt(body, int64(j), 10)
|
|
body = append(body, `"]`...)
|
|
if j < rows-1 {
|
|
body = append(body, ',')
|
|
}
|
|
}
|
|
|
|
body = append(body, `]}`...)
|
|
if i < streams-1 {
|
|
body = append(body, ',')
|
|
}
|
|
|
|
}
|
|
|
|
body = append(body, `]}`...)
|
|
|
|
return body
|
|
}
|