mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Make orgID a direct arg of writer interface (#91422)
make orgID a direct arg of writer interface
This commit is contained in:
@@ -257,7 +257,7 @@ func (r *recordingRule) tryEvaluation(ctx context.Context, ev *Evaluation, logge
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeStart := r.clock.Now()
|
writeStart := r.clock.Now()
|
||||||
err = r.writer.Write(ctx, ev.rule.Record.Metric, ev.scheduledAt, frames, ev.rule.Labels)
|
err = r.writer.Write(ctx, ev.rule.Record.Metric, ev.scheduledAt, frames, ev.rule.OrgID, ev.rule.Labels)
|
||||||
writeDur := r.clock.Now().Sub(writeStart)
|
writeDur := r.clock.Now().Sub(writeStart)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ type RulesStore interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RecordingWriter interface {
|
type RecordingWriter interface {
|
||||||
Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error
|
Write(ctx context.Context, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type schedule struct {
|
type schedule struct {
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FakeWriter struct {
|
type FakeWriter struct {
|
||||||
WriteFunc func(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error
|
WriteFunc func(ctx context.Context, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w FakeWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error {
|
func (w FakeWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error {
|
||||||
if w.WriteFunc == nil {
|
if w.WriteFunc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.WriteFunc(ctx, name, t, frames, extraLabels)
|
return w.WriteFunc(ctx, name, t, frames, orgID, extraLabels)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ import (
|
|||||||
|
|
||||||
type NoopWriter struct{}
|
type NoopWriter struct{}
|
||||||
|
|
||||||
func (w NoopWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error {
|
func (w NoopWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/grafana/dataplane/sdata/numeric"
|
"github.com/grafana/dataplane/sdata/numeric"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/m3db/prometheus_remote_client_golang/promremote"
|
"github.com/m3db/prometheus_remote_client_golang/promremote"
|
||||||
|
|
||||||
@@ -174,14 +173,9 @@ func createAuthOpts(username, password string) *httpclient.BasicAuthOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write writes the given frames to the Prometheus remote write endpoint.
|
// Write writes the given frames to the Prometheus remote write endpoint.
|
||||||
func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, extraLabels map[string]string) error {
|
func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error {
|
||||||
l := w.logger.FromContext(ctx)
|
l := w.logger.FromContext(ctx)
|
||||||
ruleKey, found := models.RuleKeyFromContext(ctx)
|
lvs := []string{fmt.Sprint(orgID), backendType}
|
||||||
if !found {
|
|
||||||
// sanity check, this should never happen
|
|
||||||
return fmt.Errorf("rule key not found in context")
|
|
||||||
}
|
|
||||||
lvs := []string{fmt.Sprint(ruleKey.OrgID), backendType}
|
|
||||||
|
|
||||||
points, err := PointsFromFrames(name, t, frames, extraLabels)
|
points, err := PointsFromFrames(name, t, frames, extraLabels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ func TestPrometheusWriter_Write(t *testing.T) {
|
|||||||
ctx := ngmodels.WithRuleKey(context.Background(), ngmodels.GenerateRuleKey(1))
|
ctx := ngmodels.WithRuleKey(context.Background(), ngmodels.GenerateRuleKey(1))
|
||||||
|
|
||||||
t.Run("error when frames are empty", func(t *testing.T) {
|
t.Run("error when frames are empty", func(t *testing.T) {
|
||||||
err := writer.Write(ctx, "test", now, emptyFrames, map[string]string{})
|
err := writer.Write(ctx, "test", now, emptyFrames, 1, map[string]string{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ func TestPrometheusWriter_Write(t *testing.T) {
|
|||||||
return promremote.WriteResult{}, clientErr
|
return promremote.WriteResult{}, clientErr
|
||||||
}
|
}
|
||||||
|
|
||||||
err := writer.Write(ctx, "test", now, frames, map[string]string{})
|
err := writer.Write(ctx, "test", now, frames, 1, map[string]string{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.ErrorIs(t, err, clientErr)
|
require.ErrorIs(t, err, clientErr)
|
||||||
})
|
})
|
||||||
@@ -184,7 +184,7 @@ func TestPrometheusWriter_Write(t *testing.T) {
|
|||||||
return promremote.WriteResult{}, nil
|
return promremote.WriteResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := writer.Write(ctx, "test", now, frames, map[string]string{"extra": "label"})
|
err := writer.Write(ctx, "test", now, frames, 1, map[string]string{"extra": "label"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ func TestPrometheusWriter_Write(t *testing.T) {
|
|||||||
return promremote.WriteResult{}, clientErr
|
return promremote.WriteResult{}, clientErr
|
||||||
}
|
}
|
||||||
|
|
||||||
err := writer.Write(ctx, "test", now, frames, map[string]string{"extra": "label"})
|
err := writer.Write(ctx, "test", now, frames, 1, map[string]string{"extra": "label"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user