Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevesy committed Apr 11, 2024
1 parent 6c380e1 commit 0721de3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions alert/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/K-Phoen/grabana/alert/queries/loki"
"github.com/K-Phoen/grabana/alert/queries/prometheus"
"github.com/K-Phoen/grabana/alert/queries/stackdriver"
"github.com/K-Phoen/grabana/target/cloudmonitoring"

Check failure on line 9 in alert/queries.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

could not import github.com/K-Phoen/grabana/target/cloudmonitoring (-: # github.com/K-Phoen/grabana/target/cloudmonitoring

Check failure on line 9 in alert/queries.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

could not import github.com/K-Phoen/grabana/target/cloudmonitoring (-: # github.com/K-Phoen/grabana/target/cloudmonitoring
"github.com/K-Phoen/sdk"
)

// WithPrometheusQuery adds a prometheus query to the alert.
Expand Down Expand Up @@ -39,6 +41,22 @@ func WithStackdriverQuery(query *stackdriver.Stackdriver) Option {
}
}

// WithStackdriverQuery adds a cloud montioring query to the alert.
func WithCloudMonitoringQuery(ref, datasource string, q cloudmonitoring.AlertModel) Option {
return func(alert *Alert) {
alert.Builder.Rules[0].GrafanaAlert.Data = append(
alert.Builder.Rules[0].GrafanaAlert.Data,
sdk.AlertQuery{
RefID: ref,
QueryType: "",
DatasourceUID: "__FILL_ME__",
RelativeTimeRange: &sdk.AlertRelativeTimeRange{},
Model: q.AlertModel(),
},
)
}
}

// WithInfluxDBQuery adds an InfluxDB query to the alert.
func WithInfluxDBQuery(ref string, query string, options ...influxdb.Option) Option {
return func(alert *Alert) {
Expand Down
5 changes: 5 additions & 0 deletions target/cloudmonitoring/cloudmonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ const (
type Target interface {
Target() *sdk.Target
}

// Target allows to return an alert model for a specific builder.
type AlertModel interface {
AlertModel() sdk.AlertModel
}
8 changes: 8 additions & 0 deletions target/cloudmonitoring/mql.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ func NewMQL(projectName, query string, options ...MQLOption) *MQL {
}

func (m *MQL) Target() *sdk.Target { return m.target }

// AlertModel implements the AlertModel interface
func (m *MQL) AlertModel() sdk.AlertModel {
return sdk.AlertModel{
QueryType: m.target.QueryType,

Check failure on line 52 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

m.target.QueryType undefined (type *sdk.Target has no field or method QueryType)

Check failure on line 52 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

m.target.QueryType undefined (type *sdk.Target has no field or method QueryType)

Check failure on line 52 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

m.target.QueryType undefined (type *sdk.Target has no field or method QueryType)

Check failure on line 52 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

m.target.QueryType undefined (type *sdk.Target has no field or method QueryType)
TimeSeriesQuery: m.target.TimeSeriesQuery,

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

unknown field TimeSeriesQuery in struct literal of type sdk.AlertModel

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

m.target.TimeSeriesQuery undefined (type *sdk.Target has no field or method TimeSeriesQuery)

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

unknown field TimeSeriesQuery in struct literal of type sdk.AlertModel

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.20)

m.target.TimeSeriesQuery undefined (type *sdk.Target has no field or method TimeSeriesQuery)

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

unknown field TimeSeriesQuery in struct literal of type sdk.AlertModel

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

m.target.TimeSeriesQuery undefined (type *sdk.Target has no field or method TimeSeriesQuery)

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

unknown field TimeSeriesQuery in struct literal of type sdk.AlertModel

Check failure on line 53 in target/cloudmonitoring/mql.go

View workflow job for this annotation

GitHub Actions / Tests (1.21)

m.target.TimeSeriesQuery undefined (type *sdk.Target has no field or method TimeSeriesQuery)
}
}
7 changes: 7 additions & 0 deletions target/cloudmonitoring/promql.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ func NewPromQL(projectName, expr string, options ...PromQLOption) *PromQL {
}

func (p *PromQL) Target() *sdk.Target { return p.target }

func (p *PromQL) AlertModel() sdk.AlertModel {
return sdk.AlertModel{
QueryType: p.target.QueryType,
PromQLQuery: p.target.PromQLQuery,
}
}
6 changes: 6 additions & 0 deletions target/cloudmonitoring/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ func NewSLO(projectName string, options ...SLOOption) *SLO {
}

func (s *SLO) Target() *sdk.Target { return s.target }
func (s *SLO) AlertModel() sdk.AlertModel {
return sdk.AlertModel{
QueryType: s.target.QueryType,
SLOQuery: s.target.SLOQuery,
}
}
8 changes: 8 additions & 0 deletions target/cloudmonitoring/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ func NewTimeSeries(projectName, metricType string, options ...TimeSeriesOption)

// Target implements the Target interface
func (t *TimeSeries) Target() *sdk.Target { return t.target }

// AlertModel implements the AlertModel interface
func (t *TimeSeries) AlertModel() sdk.AlertModel {
return sdk.AlertModel{
QueryType: t.target.QueryType,
TimeSeriesList: t.target.TimeSeriesList,
}
}

0 comments on commit 0721de3

Please sign in to comment.