Skip to content

Commit 2bff0c2

Browse files
Thomas DelbendePierreF
Thomas Delbende
authored andcommitted
Pull request #425: Upgrade Glouton to Prometheus 3.0
Merge in PRODUCT/glouton from PRODUCT-2836-upgrade-glouton-to-prometheus-3.0 to main * commit '90255a2ea8aeabfb64dca86b78683cac1db3b918': fix: don't log "error" when stopping http server chore: upgrade Prometheus to v3
2 parents 7046bd3 + 90255a2 commit 2bff0c2

File tree

15 files changed

+103
-300
lines changed

15 files changed

+103
-300
lines changed

agent/agent.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"io"
2727
"math"
2828
"net"
29+
"net/http"
2930
"net/url"
3031
"os"
3132
"path/filepath"
@@ -1375,7 +1376,7 @@ func (a *agent) run(ctx context.Context, sighupChan chan os.Signal) { //nolint:m
13751376
go func() {
13761377
defer lateTasks.Done()
13771378

1378-
if err := api.Run(lateCtx); err != nil {
1379+
if err := api.Run(lateCtx); err != nil && !errors.Is(err, http.ErrServerClosed) {
13791380
logger.V(1).Printf("Error while stopping api: %v", err)
13801381
}
13811382
}()

go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ require (
4444
github.com/prometheus/client_golang v1.21.1
4545
github.com/prometheus/client_model v0.6.1
4646
github.com/prometheus/common v0.62.0
47-
github.com/prometheus/node_exporter v1.9.0
47+
github.com/prometheus/node_exporter v1.9.1
4848
github.com/prometheus/procfs v0.16.0
49-
github.com/prometheus/prometheus v0.55.1
49+
github.com/prometheus/prometheus v0.302.1
5050
github.com/rs/cors v1.11.1
5151
github.com/shirou/gopsutil/v4 v4.25.3
5252
github.com/vishvananda/netlink v1.3.1-0.20250221194427-0af32151e72b
@@ -67,7 +67,7 @@ require (
6767
)
6868

6969
require (
70-
cel.dev/expr v0.22.1 // indirect
70+
cel.dev/expr v0.23.0 // indirect
7171
cloud.google.com/go/auth v0.15.0 // indirect
7272
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
7373
cloud.google.com/go/compute/metadata v0.6.0 // indirect
@@ -76,7 +76,7 @@ require (
7676
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2 // indirect
7777
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 // indirect
7878
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 // indirect
79-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
79+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.0 // indirect
8080
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
8181
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
8282
github.com/Masterminds/semver/v3 v3.3.1 // indirect
@@ -218,7 +218,7 @@ require (
218218
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
219219
github.com/prometheus-community/go-runit v0.1.0 // indirect
220220
github.com/prometheus/alertmanager v0.28.1 // indirect
221-
github.com/prometheus/common/sigv4 v0.1.0 // indirect
221+
github.com/prometheus/sigv4 v0.1.2 // indirect
222222
github.com/rivo/uniseg v0.4.7 // indirect
223223
github.com/robbiet480/go.nut v0.0.0-20240622015809-60e196249c53 // indirect
224224
github.com/safchain/ethtool v0.5.10 // indirect

go.sum

+36-273
Large diffs are not rendered by default.

logger/slog_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func TestSlog(t *testing.T) {
30-
// No parallel for this test since we modify the logger config
30+
// No parallelism for this test since we modify the logger config
3131
logBuf := new(bytes.Buffer)
3232

3333
err := setLogger(func() error {

prometheus/model/appendable.go

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ func (a *childrenAppender) Rollback() error {
7474
return a.parent.app.Rollback()
7575
}
7676

77+
func (a *childrenAppender) SetOptions(opts *storage.AppendOptions) {
78+
a.parent.l.Lock()
79+
defer a.parent.l.Unlock()
80+
81+
a.parent.app.SetOptions(opts)
82+
}
83+
7784
func (a *childrenAppender) AppendExemplar(ref storage.SeriesRef, l labels.Labels, e exemplar.Exemplar) (storage.SeriesRef, error) {
7885
a.parent.l.Lock()
7986
defer a.parent.l.Unlock()
@@ -88,6 +95,13 @@ func (a *childrenAppender) AppendHistogram(ref storage.SeriesRef, l labels.Label
8895
return a.parent.app.AppendHistogram(ref, l, t, h, fh)
8996
}
9097

98+
func (a *childrenAppender) AppendHistogramCTZeroSample(ref storage.SeriesRef, l labels.Labels, t, ct int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (storage.SeriesRef, error) {
99+
a.parent.l.Lock()
100+
defer a.parent.l.Unlock()
101+
102+
return a.parent.app.AppendHistogramCTZeroSample(ref, l, t, ct, h, fh)
103+
}
104+
91105
func (a *childrenAppender) UpdateMetadata(ref storage.SeriesRef, l labels.Labels, m metadata.Metadata) (storage.SeriesRef, error) {
92106
a.parent.l.Lock()
93107
defer a.parent.l.Unlock()

prometheus/model/appender.go

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ func (a *BufferAppender) rollback() {
8989
a.temp = nil
9090
}
9191

92+
func (a *BufferAppender) SetOptions(*storage.AppendOptions) {}
93+
9294
func (a *BufferAppender) FixSampleTimestamp(ts time.Time) {
9395
a.l.Lock()
9496
defer a.l.Unlock()
@@ -176,6 +178,10 @@ func (a *BufferAppender) AppendHistogram(storage.SeriesRef, labels.Labels, int64
176178
return 0, errNotImplemented
177179
}
178180

181+
func (a *BufferAppender) AppendHistogramCTZeroSample(storage.SeriesRef, labels.Labels, int64, int64, *histogram.Histogram, *histogram.FloatHistogram) (storage.SeriesRef, error) {
182+
return 0, errNotImplemented
183+
}
184+
179185
func (a *BufferAppender) UpdateMetadata(storage.SeriesRef, labels.Labels, metadata.Metadata) (storage.SeriesRef, error) {
180186
return 0, errNotImplemented
181187
}

prometheus/promql/promql.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/bleemeo/glouton/logger"
2929

3030
"github.com/go-chi/chi/v5"
31-
"github.com/go-kit/log"
3231
"github.com/grafana/regexp"
3332
jsoniter "github.com/json-iterator/go"
3433
"github.com/prometheus/common/model"
@@ -77,7 +76,6 @@ var (
7776
type PromQL struct {
7877
CORSOrigin *regexp.Regexp
7978

80-
logger log.Logger
8179
queryEngine *promql.Engine
8280
}
8381

@@ -127,9 +125,8 @@ func (p *PromQL) Register(st storage.Queryable) http.Handler {
127125
}
128126

129127
func (p *PromQL) init() {
130-
p.logger = logger.GoKitLoggerWrapper(logger.V(1))
131128
opts := promql.EngineOpts{
132-
Logger: log.With(p.logger, "component", "query engine"),
129+
Logger: logger.NewSlog().With("component", "query engine"),
133130
Reg: nil,
134131
MaxSamples: 50000000,
135132
Timeout: 2 * time.Minute,
@@ -307,7 +304,7 @@ func (p *PromQL) respond(w http.ResponseWriter, data interface{}, warnings annot
307304
Warnings: warningStrings,
308305
})
309306
if err != nil {
310-
_ = p.logger.Log("msg", "error marshaling json response", "err", err)
307+
logger.V(1).Printf("Error marshaling PromQL json response: %v", err)
311308

312309
http.Error(w, err.Error(), http.StatusInternalServerError)
313310

@@ -318,7 +315,7 @@ func (p *PromQL) respond(w http.ResponseWriter, data interface{}, warnings annot
318315
w.WriteHeader(http.StatusOK)
319316

320317
if _, err := w.Write(b); err != nil {
321-
_ = p.logger.Log("msg", "error writing response", "err", err)
318+
logger.V(1).Printf("Error writing PromQL response: %v", err)
322319
}
323320
}
324321

@@ -332,7 +329,7 @@ func (p *PromQL) respondError(w http.ResponseWriter, apiErr *apiError, data inte
332329
Data: data,
333330
})
334331
if err != nil {
335-
_ = p.logger.Log("msg", "error marshaling json response", "err", err)
332+
logger.V(1).Printf("Error marshaling PromQL error json response: %v", err)
336333

337334
http.Error(w, err.Error(), http.StatusInternalServerError)
338335

@@ -360,6 +357,6 @@ func (p *PromQL) respondError(w http.ResponseWriter, apiErr *apiError, data inte
360357
w.WriteHeader(code)
361358

362359
if _, err := w.Write(b); err != nil {
363-
_ = p.logger.Log("msg", "error writing response", "err", err)
360+
logger.V(1).Printf("Error writing PromQL error response: %v", err)
364361
}
365362
}

prometheus/registry/internal/ruler/ruler.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/bleemeo/glouton/store"
2929
"github.com/bleemeo/glouton/types"
3030

31-
"github.com/go-kit/log"
3231
dto "github.com/prometheus/client_model/go"
3332
"github.com/prometheus/prometheus/promql"
3433
"github.com/prometheus/prometheus/rules"
@@ -54,9 +53,8 @@ func New(input []*rules.RecordingRule) *SimpleRuler {
5453
matchers = append(matchers, matcher.MatchersFromQuery(rr.Query())...)
5554
}
5655

57-
promLogger := logger.GoKitLoggerWrapper(logger.V(1))
5856
engine := promql.NewEngine(promql.EngineOpts{
59-
Logger: log.With(promLogger, "component", "query engine"),
57+
Logger: logger.NewSlog().With("component", "query engine"),
6058
Reg: nil,
6159
MaxSamples: 50000000,
6260
Timeout: 2 * time.Minute,

prometheus/registry/internal/ruler/ruler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestApplyRulesMFS(t *testing.T) {
135135
Value: proto.String("softwareLoopback"),
136136
},
137137
},
138-
Untyped: &dto.Untyped{Value: proto.Float64(13420.4)},
138+
Untyped: &dto.Untyped{Value: proto.Float64(13556.177777777777)},
139139
TimestampMs: proto.Int64(now.UnixMilli()),
140140
},
141141
},

prometheus/rules/appendable.go

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func (a errAppender) Rollback() error {
6767
return errNotAvailable
6868
}
6969

70+
func (a errAppender) SetOptions(*storage.AppendOptions) {}
71+
7072
func (a errAppender) AppendExemplar(storage.SeriesRef, labels.Labels, exemplar.Exemplar) (storage.SeriesRef, error) {
7173
return 0, errNotAvailable
7274
}
@@ -75,6 +77,10 @@ func (a errAppender) AppendHistogram(storage.SeriesRef, labels.Labels, int64, *h
7577
return 0, errNotAvailable
7678
}
7779

80+
func (a errAppender) AppendHistogramCTZeroSample(storage.SeriesRef, labels.Labels, int64, int64, *histogram.Histogram, *histogram.FloatHistogram) (storage.SeriesRef, error) {
81+
return 0, errNotAvailable
82+
}
83+
7884
func (a errAppender) UpdateMetadata(storage.SeriesRef, labels.Labels, metadata.Metadata) (storage.SeriesRef, error) {
7985
return 0, errNotAvailable
8086
}

prometheus/rules/manager.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/bleemeo/glouton/prometheus/registry"
3030
"github.com/bleemeo/glouton/types"
3131

32-
"github.com/go-kit/log"
3332
"github.com/prometheus/prometheus/model/labels"
3433
"github.com/prometheus/prometheus/promql"
3534
"github.com/prometheus/prometheus/promql/parser"
@@ -45,7 +44,6 @@ type Manager struct {
4544
appendable *dynamicAppendable
4645
queryable storage.Queryable
4746
engine *promql.Engine
48-
logger log.Logger
4947

5048
l sync.Mutex
5149
agentStarted time.Time
@@ -76,9 +74,8 @@ func NewManager(ctx context.Context, queryable storage.Queryable, baseRules map[
7674
}
7775

7876
func newManager(ctx context.Context, queryable storage.Queryable, defaultRules map[string]string, created time.Time) *Manager {
79-
promLogger := logger.GoKitLoggerWrapper(logger.V(1))
8077
engine := promql.NewEngine(promql.EngineOpts{
81-
Logger: log.With(promLogger, "component", "query engine"),
78+
Logger: logger.NewSlog().With("component", "query engine"),
8279
Reg: nil,
8380
MaxSamples: 50000000,
8481
Timeout: 2 * time.Minute,
@@ -110,7 +107,7 @@ func newManager(ctx context.Context, queryable storage.Queryable, defaultRules m
110107
ShouldRestore: true,
111108
Opts: &rules.ManagerOptions{
112109
Context: ctx,
113-
Logger: log.With(promLogger, "component", "rules manager"),
110+
Logger: logger.NewSlog().With("component", "rules manager"),
114111
Appendable: app,
115112
Queryable: queryable,
116113
QueryFunc: rules.EngineQueryFunc(engine, queryable),
@@ -128,7 +125,6 @@ func newManager(ctx context.Context, queryable storage.Queryable, defaultRules m
128125
engine: engine,
129126
recordingRules: []*rules.Group{defaultGroup},
130127
matchers: matchers,
131-
logger: promLogger,
132128
agentStarted: created,
133129
}
134130

prometheus/rules/manager_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func (a *mockAppender) Rollback() error {
9797
return nil
9898
}
9999

100+
func (a *mockAppender) SetOptions(*storage.AppendOptions) {}
101+
100102
func (a *mockAppender) AppendExemplar(storage.SeriesRef, labels.Labels, exemplar.Exemplar) (storage.SeriesRef, error) {
101103
return 0, errNotImplemented
102104
}
@@ -105,6 +107,10 @@ func (a *mockAppender) AppendHistogram(storage.SeriesRef, labels.Labels, int64,
105107
return 0, errNotImplemented
106108
}
107109

110+
func (a *mockAppender) AppendHistogramCTZeroSample(storage.SeriesRef, labels.Labels, int64, int64, *histogram.Histogram, *histogram.FloatHistogram) (storage.SeriesRef, error) {
111+
return 0, errNotImplemented
112+
}
113+
108114
func (a *mockAppender) UpdateMetadata(storage.SeriesRef, labels.Labels, metadata.Metadata) (storage.SeriesRef, error) {
109115
return 0, errNotImplemented
110116
}

prometheus/scrapper/scrapper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func parserReader(data []byte, filter func(lbls labels.Labels) bool) ([]*dto.Met
185185
err error
186186
)
187187

188-
p, err := textparse.New(data, "", true, nil)
188+
p, err := textparse.New(data, "text/plain", "", false, true, nil)
189189
if err != nil {
190190
return nil, err
191191
}

prometheus/scrapper/scrapper_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"path/filepath"
2626
"sort"
27+
"strconv"
2728
"testing"
2829

2930
"github.com/bleemeo/glouton/types"
@@ -422,7 +423,7 @@ func flattenHistogramAndSummary(mfs []*dto.MetricFamily) []*dto.MetricFamily {
422423
metric.GetLabel(),
423424
&dto.LabelPair{
424425
Name: proto.String("le"),
425-
Value: proto.String(fmt.Sprint(b.GetUpperBound())),
426+
Value: proto.String(formatFloat(b.GetUpperBound())),
426427
},
427428
),
428429
Untyped: &dto.Untyped{
@@ -500,6 +501,15 @@ func flattenHistogramAndSummary(mfs []*dto.MetricFamily) []*dto.MetricFamily {
500501
return flatMFS
501502
}
502503

504+
func formatFloat(f float64) string {
505+
res := strconv.FormatFloat(f, 'f', -1, 64)
506+
if math.Round(f) != f || math.IsInf(f, 1) || math.IsInf(f, -1) {
507+
return res
508+
}
509+
510+
return res + ".0"
511+
}
512+
503513
func Benchmark_parserReader(b *testing.B) {
504514
for _, filename := range []string{"sample.txt", "large.txt"} {
505515
for _, useRef := range []bool{true, false} {

store/appendable.go

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func (a appender) Rollback() error {
6868
return errNotImplemented
6969
}
7070

71+
func (a appender) SetOptions(*storage.AppendOptions) {}
72+
7173
func (a appender) AppendExemplar(storage.SeriesRef, labels.Labels, exemplar.Exemplar) (storage.SeriesRef, error) {
7274
return 0, errNotImplemented
7375
}
@@ -76,6 +78,10 @@ func (a appender) AppendHistogram(storage.SeriesRef, labels.Labels, int64, *hist
7678
return 0, errNotImplemented
7779
}
7880

81+
func (a appender) AppendHistogramCTZeroSample(storage.SeriesRef, labels.Labels, int64, int64, *histogram.Histogram, *histogram.FloatHistogram) (storage.SeriesRef, error) {
82+
return 0, errNotImplemented
83+
}
84+
7985
func (a appender) UpdateMetadata(storage.SeriesRef, labels.Labels, metadata.Metadata) (storage.SeriesRef, error) {
8086
return 0, errNotImplemented
8187
}

0 commit comments

Comments
 (0)