Skip to content

Update to Prometheus 3.3 (& Loki 3.5) #3454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 103 additions & 109 deletions go.mod

Large diffs are not rendered by default.

891 changes: 232 additions & 659 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/component/common/kubernetes/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func parseRuleGroups(t *testing.T, buf []byte) []rulefmt.RuleGroup {
t.Helper()

groups, errs := rulefmt.Parse(buf)
groups, errs := rulefmt.Parse(buf, false)
require.Empty(t, errs)

return groups.Groups
Expand Down
4 changes: 3 additions & 1 deletion internal/component/common/loki/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package wal

import (
"fmt"
"log/slog"
"os"

"github.com/go-kit/log"
"github.com/grafana/loki/v3/pkg/ingester/wal"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/tsdb/wlog"

"github.com/grafana/alloy/internal/runtime/logging"
"github.com/grafana/alloy/internal/runtime/logging/level"
)

Expand Down Expand Up @@ -37,7 +39,7 @@ type wrapper struct {
func New(cfg Config, log log.Logger, registerer prometheus.Registerer) (WAL, error) {
// TODO: We should fine-tune the WAL instantiated here to allow some buffering of written entries, but not written to disk
// yet. This will attest for the lack of buffering in the channel Writer exposes.
tsdbWAL, err := wlog.NewSize(log, registerer, cfg.Dir, wlog.DefaultSegmentSize, wlog.CompressionSnappy)
tsdbWAL, err := wlog.NewSize(slog.New(logging.NewSlogGoKitHandler(log)), registerer, cfg.Dir, wlog.DefaultSegmentSize, wlog.CompressionSnappy)
if err != nil {
return nil, fmt.Errorf("failde to create tsdb WAL: %w", err)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/component/common/loki/wal/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"math"
"os"
"strconv"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/prometheus/prometheus/tsdb/wlog"

"github.com/grafana/alloy/internal/component/common/loki/wal/internal"
"github.com/grafana/alloy/internal/runtime/logging"
"github.com/grafana/alloy/internal/runtime/logging/level"
)

Expand Down Expand Up @@ -205,7 +207,7 @@ func (w *Watcher) watch(segmentNum int, tail bool) error {
}
defer segment.Close()

reader := wlog.NewLiveReader(w.logger, nil, segment)
reader := wlog.NewLiveReader(slog.New(logging.NewSlogGoKitHandler(w.logger)), nil, segment)

readTimer := newBackoffTimer(w.minReadFreq, w.maxReadFreq)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net"
"net/http"
"strconv"
Expand All @@ -27,11 +28,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/strutil"

"github.com/grafana/alloy/internal/runtime/logging/level"
"github.com/grafana/alloy/internal/slogadapter"
)

const (
Expand Down Expand Up @@ -164,9 +167,9 @@ type Discovery struct {
}

// NewDiscovery returns a new Discovery for the given config.
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
func NewDiscovery(conf *SDConfig, logger *slog.Logger) (*Discovery, error) {
if logger == nil {
logger = log.NewNopLogger()
logger = promslog.NewNopLogger()
}

tls, err := config.NewTLSConfig(&conf.TLSConfig)
Expand Down Expand Up @@ -209,7 +212,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
refreshInterval: time.Duration(conf.RefreshInterval),
clientDatacenter: conf.Datacenter,
finalizer: transport.CloseIdleConnections,
logger: logger,
logger: slogadapter.GoKit(logger.Handler()),
}
return cd, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"testing"
"time"

"github.com/go-kit/log"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

Expand Down Expand Up @@ -341,7 +341,7 @@ func newServer(t *testing.T) (*httptest.Server, *SDConfig) {
}

func newDiscovery(t *testing.T, config *SDConfig) *Discovery {
logger := log.NewNopLogger()
logger := promslog.NewNopLogger()
d, err := NewDiscovery(config, logger)
require.NoError(t, err)
return d
Expand Down
4 changes: 3 additions & 1 deletion internal/component/discovery/discovery_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package discovery

import (
"context"
"log/slog"

"github.com/go-kit/log"
"github.com/grafana/alloy/internal/runtime/logging"
"github.com/prometheus/client_golang/prometheus"
promdiscovery "github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/targetgroup"
Expand All @@ -27,7 +29,7 @@ func NewDiscovererWithMetrics(cfg promdiscovery.Config, reg prometheus.Registere
sdMetrics := cfg.NewDiscovererMetrics(reg, refreshMetrics)

discoverer, err := cfg.NewDiscoverer(promdiscovery.DiscovererOptions{
Logger: logger,
Logger: slog.New(logging.NewSlogGoKitHandler(logger)),
Metrics: sdMetrics,
})

Expand Down
4 changes: 3 additions & 1 deletion internal/component/discovery/kubelet/discoverer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package kubelet

import (
"fmt"
"log/slog"

"github.com/prometheus/client_golang/prometheus"
prom_discovery "github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/refresh"

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/runtime/logging"
)

type kubeletDiscoveryConfig struct {
Expand Down Expand Up @@ -40,7 +42,7 @@ func (k *kubeletDiscoveryConfig) NewDiscoverer(discOpts prom_discovery.Discovere
}

return refresh.NewDiscovery(refresh.Options{
Logger: k.opts.Logger,
Logger: slog.New(logging.NewSlogGoKitHandler(k.opts.Logger)),
Mech: "kubelet",
Interval: interval,
RefreshF: kubeletDiscovery.Refresh,
Expand Down
2 changes: 1 addition & 1 deletion internal/component/loki/rules/kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func convertCRDRuleGroupToRuleGroup(crd promv1.PrometheusRuleSpec) ([]rulefmt.Ru
return nil, err
}

groups, _ := rulefmt.Parse(buf)
groups, _ := rulefmt.Parse(buf, false)

// Disable looking for errors, loki queries won't be valid prometheus queries, but still want the similar information
//if len(errs) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ func (s *PushAPIServer) handleLoki(w http.ResponseWriter, r *http.Request) {
logger,
tenantID,
r,
nil, // tenants retention
push.EmptyLimits{},
push.ParseLokiRequest,
nil, // usage tracker
nil,
false,
)
if err != nil {
level.Warn(s.logger).Log("msg", "failed to parse incoming push request", "err", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions internal/component/mimir/rules/kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ func (e *eventProcessor) desiredStateFromKubernetes() (kubernetes.RuleGroupsByNa
if e.extraQueryMatchers != nil {
for _, ruleGroup := range groups {
for i := range ruleGroup.Rules {
query := ruleGroup.Rules[i].Expr.Value
query := ruleGroup.Rules[i].Expr
newQuery, err := addMatchersToQuery(query, e.extraQueryMatchers.Matchers)
if err != nil {
level.Error(e.logger).Log("msg", "failed to add labels to PrometheusRule query", "query", query, "err", err)
}
ruleGroup.Rules[i].Expr.Value = newQuery
ruleGroup.Rules[i].Expr = newQuery
}
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func convertCRDRuleGroupToRuleGroup(crd promv1.PrometheusRuleSpec) ([]rulefmt.Ru
return nil, err
}

groups, errs := rulefmt.Parse(buf)
groups, errs := rulefmt.Parse(buf, false)
if len(errs) > 0 {
return nil, multierror.Append(nil, errs...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ type dataPoint struct {
// internalMetricMetadata allows looking up metadata for internal scrape metrics
var internalMetricMetadata = map[string]*scrape.MetricMetadata{
scrapeUpMetricName: {
Metric: scrapeUpMetricName,
Type: model.MetricTypeGauge,
Help: "The scraping was successful",
MetricFamily: scrapeUpMetricName,
Type: model.MetricTypeGauge,
Help: "The scraping was successful",
},
"scrape_duration_seconds": {
Metric: "scrape_duration_seconds",
Unit: "seconds",
Type: model.MetricTypeGauge,
Help: "Duration of the scrape",
MetricFamily: "scrape_duration_seconds",
Unit: "seconds",
Type: model.MetricTypeGauge,
Help: "Duration of the scrape",
},
"scrape_samples_scraped": {
Metric: "scrape_samples_scraped",
Type: model.MetricTypeGauge,
Help: "The number of samples the target exposed",
MetricFamily: "scrape_samples_scraped",
Type: model.MetricTypeGauge,
Help: "The number of samples the target exposed",
},
"scrape_series_added": {
Metric: "scrape_series_added",
Type: model.MetricTypeGauge,
Help: "The approximate number of new series in this scrape",
MetricFamily: "scrape_series_added",
Type: model.MetricTypeGauge,
Help: "The approximate number of new series in this scrape",
},
"scrape_samples_post_metric_relabeling": {
Metric: "scrape_samples_post_metric_relabeling",
Type: model.MetricTypeGauge,
Help: "The number of samples remaining after metric relabeling was applied",
MetricFamily: "scrape_samples_post_metric_relabeling",
Type: model.MetricTypeGauge,
Help: "The number of samples remaining after metric relabeling was applied",
},
}

Expand All @@ -61,7 +61,7 @@ func metadataForMetric(metricName string, mc scrape.MetricMetadataStore) (*scrap
}
// Otherwise, the metric is unknown
return &scrape.MetricMetadata{
Metric: metricName,
Type: model.MetricTypeUnknown,
MetricFamily: metricName,
Type: model.MetricTypeUnknown,
}, metricName
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels
mg.ts = t
mg.count = v
mg.hasCount = true
case metricName == mf.metadata.Metric+metricSuffixCreated:
case metricName == mf.metadata.MetricFamily+metricSuffixCreated:
mg.created = v
default:
boundary, err := getBoundary(mf.mtype, ls)
Expand All @@ -407,11 +407,11 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels
mg.complexValue = append(mg.complexValue, &dataPoint{value: v, boundary: boundary})
}
case pmetric.MetricTypeExponentialHistogram:
if metricName == mf.metadata.Metric+metricSuffixCreated {
if metricName == mf.metadata.MetricFamily+metricSuffixCreated {
mg.created = v
}
case pmetric.MetricTypeSum:
if metricName == mf.metadata.Metric+metricSuffixCreated {
if metricName == mf.metadata.MetricFamily+metricSuffixCreated {
mg.created = v
} else {
mg.value = v
Expand Down
Loading
Loading