mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
The prompb and prompbmarshal share exactly the same models and provide
marshal and unmarshale capabilities for them. This creates duplication
(changes in one model has to be made in another, case with metadata) and
confusion where for example you compare same looking models but golang
says they are not the same (because of the type).
This commit merge prompbmarshal logic into prompb so the rest of the
code is aligned on prompb models.
Moves samplesPool and labelsPool to WriteRequestUnmarshaller.
Make WriteRequest struct clean from unmarshal logic.
The benchmark shows no significant changes:
$benchstat prompbmarshal.bench prompb2.bench
goos: darwin
goarch: arm64
pkg: github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb
cpu: Apple M1 Pro
│ prompbmarshal.bench │ prompb2.bench │
│ sec/op │ sec/op vs base │
WriteRequestUnmarshalProtobuf-10 189.2µ ± 5% 190.8µ ± 8% ~ (p=0.579 n=10)
WriteRequestMarshalProtobuf-10 145.3µ ± 7% 143.6µ ± 2% ~ (p=0.143 n=10)
geomean 165.8µ 165.5µ -0.14%
│ prompbmarshal.bench │ prompb2.bench │
│ B/s │ B/s vs base │
WriteRequestUnmarshalProtobuf-10 50.42Mi ± 5% 49.99Mi ± 8% ~ (p=0.593 n=10)
WriteRequestMarshalProtobuf-10 65.64Mi ± 7% 66.39Mi ± 2% ~ (p=0.143 n=10)
geomean 57.53Mi 57.61Mi +0.14%
│ prompbmarshal.bench │ prompb2.bench │
│ B/op │ B/op vs base │
WriteRequestUnmarshalProtobuf-10 27.70Ki ± 4% 26.90Ki ± 7% ~ (p=0.190 n=10)
WriteRequestMarshalProtobuf-10 3.267Ki ± 12% 3.273Ki ± 12% ~ (p=0.971 n=10)
geomean 9.514Ki 9.383Ki -1.38%
│ prompbmarshal.bench │ prompb2.bench │
│ allocs/op │ allocs/op vs base │
WriteRequestUnmarshalProtobuf-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
WriteRequestMarshalProtobuf-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
141 lines
5.2 KiB
Go
141 lines
5.2 KiB
Go
// Code generated by qtc from "alertmanager_request.qtpl". DO NOT EDIT.
|
|
// See https://github.com/valyala/quicktemplate for details.
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:1
|
|
package notifier
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:1
|
|
import (
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb"
|
|
)
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:8
|
|
import (
|
|
qtio422016 "io"
|
|
|
|
qt422016 "github.com/valyala/quicktemplate"
|
|
)
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:8
|
|
var (
|
|
_ = qtio422016.Copy
|
|
_ = qt422016.AcquireByteBuffer
|
|
)
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:8
|
|
func streamamRequest(qw422016 *qt422016.Writer, alerts []Alert, generatorURL func(Alert) string, lblss [][]prompb.Label) {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:8
|
|
qw422016.N().S(`[`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:10
|
|
for i, alert := range alerts {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:11
|
|
lbls := lblss[i]
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:11
|
|
qw422016.N().S(`{"startsAt":`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:13
|
|
qw422016.N().Q(alert.Start.Format(time.RFC3339Nano))
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:13
|
|
qw422016.N().S(`,"generatorURL":`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:14
|
|
qw422016.N().Q(generatorURL(alert))
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:14
|
|
qw422016.N().S(`,`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:15
|
|
if !alert.End.IsZero() {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:15
|
|
qw422016.N().S(`"endsAt":`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:16
|
|
qw422016.N().Q(alert.End.Format(time.RFC3339Nano))
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:16
|
|
qw422016.N().S(`,`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:17
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:17
|
|
qw422016.N().S(`"labels": {`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:19
|
|
ll := len(lbls)
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:20
|
|
for idx, l := range lbls {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
qw422016.N().Q(l.Name)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
qw422016.N().S(`:`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
qw422016.N().Q(l.Value)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
if idx != ll-1 {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
qw422016.N().S(`,`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:21
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:22
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:22
|
|
qw422016.N().S(`},"annotations": {`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:25
|
|
c := len(alert.Annotations)
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:26
|
|
for k, v := range alert.Annotations {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:27
|
|
c = c - 1
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
qw422016.N().Q(k)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
qw422016.N().S(`:`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
qw422016.N().Q(v)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
if c > 0 {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
qw422016.N().S(`,`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:28
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:29
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:29
|
|
qw422016.N().S(`}}`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:32
|
|
if i != len(alerts)-1 {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:32
|
|
qw422016.N().S(`,`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:32
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:33
|
|
}
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:33
|
|
qw422016.N().S(`]`)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
}
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
func writeamRequest(qq422016 qtio422016.Writer, alerts []Alert, generatorURL func(Alert) string, lblss [][]prompb.Label) {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
qw422016 := qt422016.AcquireWriter(qq422016)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
streamamRequest(qw422016, alerts, generatorURL, lblss)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
qt422016.ReleaseWriter(qw422016)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
}
|
|
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
func amRequest(alerts []Alert, generatorURL func(Alert) string, lblss [][]prompb.Label) string {
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
qb422016 := qt422016.AcquireByteBuffer()
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
writeamRequest(qb422016, alerts, generatorURL, lblss)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
qs422016 := string(qb422016.B)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
qt422016.ReleaseByteBuffer(qb422016)
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
return qs422016
|
|
//line app/vmalert/notifier/alertmanager_request.qtpl:35
|
|
}
|