Skip to content

Commit ecdc0e0

Browse files
authored
PMM-13943 Provide a UID per datasource (#3926)
* PMM-13493 Provide a UID per datasource * PMM-13943 Revert prior removal of DS * PMM-13943 remove a redundant grafana method * PMM-13943 remove datasource prior to adding them
1 parent e3f0525 commit ecdc0e0

File tree

5 files changed

+12
-49
lines changed

5 files changed

+12
-49
lines changed

build/ansible/roles/grafana/files/datasources.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
apiVersion: 1
22
deleteDatasources:
3+
- name: Metrics
4+
orgId: 1
5+
- name: PostgreSQL
6+
orgId: 1
7+
- name: PTSummary
8+
orgId: 1
39
- name: ClickHouse
410
orgId: 1
511

@@ -8,6 +14,7 @@ datasources:
814
version: 2
915
orgId: 1
1016
type: prometheus
17+
uid: prometheus
1118
access: proxy
1219
url: http://127.0.0.1:8430/
1320
isDefault: true
@@ -20,6 +27,7 @@ datasources:
2027
version: 2
2128
orgId: 1
2229
type: postgres
30+
uid: postgres
2331
access: proxy
2432
url: ${PMM_POSTGRES_ADDR}
2533
user: ${PMM_POSTGRES_USERNAME}
@@ -37,13 +45,15 @@ datasources:
3745
version: 2
3846
orgId: 1
3947
type: pmm-pt-summary-datasource
48+
uid: pt-summary
4049
access: proxy
4150

4251
# https://github.com/grafana/clickhouse-datasource?tab=readme-ov-file#with-a-configuration-file
4352
- name: ClickHouse
4453
orgId: 1
4554
version: 2
4655
type: grafana-clickhouse-datasource
56+
uid: clickhouse
4757
jsonData:
4858
username: ${PMM_CLICKHOUSE_USER}
4959
port: ${PMM_CLICKHOUSE_PORT}

managed/services/alerting/deps.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ import (
2525

2626
type grafanaClient interface {
2727
CreateAlertRule(ctx context.Context, folderUID, groupName, interval string, rule *services.Rule) error
28-
GetDatasourceUIDByID(ctx context.Context, id int64) (string, error)
2928
GetFolderByUID(ctx context.Context, uid string) (*gapi.Folder, error)
3029
}

managed/services/alerting/mock_grafana_client_test.go

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

managed/services/alerting/service.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const (
5151
builtinTemplatesDir = "/usr/local/percona/alerting-templates"
5252
userTemplatesDir = "/srv/alerting/templates"
5353
defaultEvaluationInterval = time.Minute
54+
prometheusDatasourceUID = "prometheus"
5455

5556
dirPerm = os.FileMode(0o775)
5657
)
@@ -612,11 +613,6 @@ func (s *Service) CreateRule(ctx context.Context, req *alerting.CreateRuleReques
612613
return nil, status.Error(codes.InvalidArgument, "Rule group name should be specified.")
613614
}
614615

615-
metricsDatasourceUID, err := s.grafanaClient.GetDatasourceUIDByID(ctx, 1) // 1 - it's id of Metrics datasource in PMM
616-
if err != nil {
617-
return nil, err
618-
}
619-
620616
sourceTemplate, ok := s.GetTemplates()[req.TemplateName]
621617
if !ok {
622618
return nil, status.Errorf(codes.NotFound, "Unknown template %s.", req.TemplateName)
@@ -693,7 +689,7 @@ func (s *Service) CreateRule(ctx context.Context, req *alerting.CreateRuleReques
693689
Data: []services.Data{
694690
{
695691
RefID: "A",
696-
DatasourceUID: metricsDatasourceUID,
692+
DatasourceUID: prometheusDatasourceUID,
697693
// TODO: https://community.grafana.com/t/grafana-requires-time-range-for-alert-rule-creation-with-instant-promql-quieriy/70919
698694
RelativeTimeRange: services.RelativeTimeRange{From: 600, To: 0},
699695
Model: services.Model{

managed/services/grafana/client.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -533,20 +533,6 @@ func validateDurations(intervalD, forD string) error {
533533
return nil
534534
}
535535

536-
// GetDatasourceUIDByID returns grafana datasource UID.
537-
func (c *Client) GetDatasourceUIDByID(ctx context.Context, id int64) (string, error) {
538-
grafanaClient, err := c.createGrafanaClient(ctx)
539-
if err != nil {
540-
return "", errors.Wrap(err, "failed to create grafana client")
541-
}
542-
543-
ds, err := grafanaClient.DataSource(id)
544-
if err != nil {
545-
return "", err
546-
}
547-
return ds.UID, nil
548-
}
549-
550536
// CreateFolder creates grafana folder.
551537
func (c *Client) CreateFolder(ctx context.Context, title string) (*gapi.Folder, error) {
552538
grafanaClient, err := c.createGrafanaClient(ctx)

0 commit comments

Comments
 (0)