Skip to content

Commit

Permalink
Merge branch 'main' into CRE-43_incorrect_slicing_pullOneoff
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso authored Jan 13, 2025
2 parents 21f5354 + 7c712f1 commit 84d1fe2
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
2 changes: 2 additions & 0 deletions observability-lib/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/smartcontractkit/chainlink-common/observability-lib/cmd/api/contact_point"
"github.com/smartcontractkit/chainlink-common/observability-lib/cmd/api/dashboard"
"github.com/smartcontractkit/chainlink-common/observability-lib/cmd/api/notification_policy"
"github.com/smartcontractkit/chainlink-common/observability-lib/cmd/api/rule"
"github.com/spf13/cobra"
)

Expand All @@ -16,6 +17,7 @@ func init() {
Cmd.AddCommand(contact_point.Cmd)
Cmd.AddCommand(dashboard.Cmd)
Cmd.AddCommand(notification_policy.Cmd)
Cmd.AddCommand(rule.Cmd)

Cmd.PersistentFlags().String("grafana-url", "", "Grafana URL")
errURL := Cmd.MarkPersistentFlagRequired("grafana-url")
Expand Down
24 changes: 24 additions & 0 deletions observability-lib/cmd/api/rule/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rule

import (
"github.com/smartcontractkit/chainlink-common/observability-lib/api"
"github.com/spf13/cobra"
)

var deleteCmd = &cobra.Command{
Use: "delete [name]",
Short: "Delete rule by UID",
RunE: func(cmd *cobra.Command, args []string) error {
grafanaClient := api.NewClient(
cmd.Flag("grafana-url").Value.String(),
cmd.Flag("grafana-token").Value.String(),
)

_, _, errDelete := grafanaClient.DeleteAlertRule(args[0])
if errDelete != nil {
return errDelete
}

return nil
},
}
14 changes: 14 additions & 0 deletions observability-lib/cmd/api/rule/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package rule

import (
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "rule [actions]",
Short: "Perform actions on dashboard",
}

func init() {
Cmd.AddCommand(deleteCmd)
}
7 changes: 6 additions & 1 deletion observability-lib/grafana/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type RuleQuery struct {
RefID string
Datasource string
LegendFormat string
TimeRange int64
Instant bool
}

Expand All @@ -20,9 +21,13 @@ func newRuleQuery(query RuleQuery) *alerting.QueryBuilder {
query.LegendFormat = "__auto"
}

if query.TimeRange == 0 {
query.TimeRange = 600
}

res := alerting.NewQueryBuilder(query.RefID).
DatasourceUid(query.Datasource).
RelativeTimeRange(600, 0) // TODO
RelativeTimeRange(alerting.Duration(query.TimeRange), alerting.Duration(0))

model := prometheus.NewDataqueryBuilder().
Expr(query.Expr).
Expand Down
49 changes: 35 additions & 14 deletions observability-lib/grafana/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,21 @@ func newToolTip(options *ToolTipOptions) *common.VizTooltipOptionsBuilder {
}

type PanelOptions struct {
Datasource string
Title string
Description string
Span uint32
Height uint32
Decimals float64
Unit string
NoValue string
Min *float64
Max *float64
Query []Query
Threshold *ThresholdOptions
Transform *TransformOptions
ColorScheme dashboard.FieldColorModeId
Datasource string
Title string
Description string
Span uint32
Height uint32
Decimals float64
Unit string
NoValue string
Min *float64
Max *float64
MaxDataPoints *float64
Query []Query
Threshold *ThresholdOptions
Transform *TransformOptions
ColorScheme dashboard.FieldColorModeId
}

type Panel struct {
Expand Down Expand Up @@ -214,6 +215,10 @@ func NewStatPanel(options *StatPanelOptions) *Panel {
Mappings(options.Mappings).
ReduceOptions(common.NewReduceDataOptionsBuilder().Calcs([]string{"last"}))

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
}

if options.Min != nil {
newPanel.Min(*options.Min)
}
Expand Down Expand Up @@ -296,6 +301,10 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel {
).
Tooltip(newToolTip(options.ToolTipOptions))

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
}

if options.Min != nil {
newPanel.Min(*options.Min)
}
Expand Down Expand Up @@ -363,6 +372,10 @@ func NewGaugePanel(options *GaugePanelOptions) *Panel {
Calcs([]string{"lastNotNull"}).Values(false),
)

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
}

if options.Min != nil {
newPanel.Min(*options.Min)
}
Expand Down Expand Up @@ -405,6 +418,10 @@ func NewTablePanel(options *TablePanelOptions) *Panel {
Unit(options.Unit).
NoValue(options.NoValue)

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
}

if options.Min != nil {
newPanel.Min(*options.Min)
}
Expand Down Expand Up @@ -451,6 +468,10 @@ func NewLogPanel(options *LogPanelOptions) *Panel {
NoValue(options.NoValue).
PrettifyLogMessage(options.PrettifyJSON)

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
}

if options.Min != nil {
newPanel.Min(*options.Min)
}
Expand Down

0 comments on commit 84d1fe2

Please sign in to comment.