Skip to content

Commit

Permalink
DEV-45405 - Fix grafana tests (#29)
Browse files Browse the repository at this point in the history
fix the failing grafana unit tests so we can have green pipeline

tests fixed:
* api_notification_channel_test.go - fixed to expected strings returned from notifications
* error_handling_test.go - fixed expected response due to our change in errors
* api_plugins_test.go - updated the expectedListResp.json
* dashboard_test.go - TestDashboardVersionsAPIEndpoint
* templates_test.go - removed orgId from urls

also:
* changed implementation in alertmanager.go NewAlertmanager() to avoid null exception if there is no ParsedAppUrl provided in config (fixes a lot of tests)
* changed implementation in navtree.go to remove the connections section (datasources) in another place, to help tests pass and makes more sense.
  • Loading branch information
yasmin-tr authored Oct 6, 2024
1 parent f03c278 commit ada530d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pkg/api/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func TestDashboardVersionsAPIEndpoint(t *testing.T) {
},
}
getHS(&usertest.FakeUserService{
ExpectedUser: &user.User{ID: 1, Login: "test-user"},
ExpectedUser: &user.User{ID: 1, Name: "test-user"}, // LOGZ.IO GRAFANA CHANGE :: DEV-43349 - user.Login to usr.Name as login field
}).callGetDashboardVersions(sc)

assert.Equal(t, http.StatusOK, sc.resp.Code)
Expand Down
10 changes: 6 additions & 4 deletions pkg/services/navtree/navtreeimpl/navtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ func (s *ServiceImpl) GetNavTree(c *contextmodel.ReqContext, prefs *pref.Prefere
}
}

if connectionsSection := s.buildDataConnectionsNavLink(c); connectionsSection != nil {
treeRoot.AddSection(connectionsSection)
}
// LOGZ.IO GRAFANA CHANGE :: DEV-45139 - hide datasources menu
//if connectionsSection := s.buildDataConnectionsNavLink(c); connectionsSection != nil {
// treeRoot.AddSection(connectionsSection)
//}
// LOGZ.IO GRAFANA CHANGE :: End

orgAdminNode, err := s.getAdminNode(c)

Expand Down Expand Up @@ -485,7 +487,7 @@ func (s *ServiceImpl) buildDataConnectionsNavLink(c *contextmodel.ReqContext) *n

baseUrl := s.cfg.AppSubURL + "/connections"

if false && hasAccess(datasources.ConfigurationPageAccess) { // LOGZ.IO GRAFANA CHANGE :: hide datasources menu, should be done by altering permissions
if hasAccess(datasources.ConfigurationPageAccess) {
// Add new connection
children = append(children, &navtree.NavLink{
Id: "connections-add-new-connection",
Expand Down
11 changes: 10 additions & 1 deletion pkg/services/ngalert/notifier/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,18 @@ func NewAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
},
}

// LOGZ.IO GRAFANA CHANGE :: DEV-43657 - Set APP url to logzio grafana for alert notification URLs
externalUrl := ""
if cfg.ParsedAppURL != nil {
externalUrl = cfg.ParsedAppURL.String()
} else {
externalUrl = cfg.AppURL
}
// LOGZ.IO GRAFANA CHANGE :: End

amcfg := &alertingNotify.GrafanaAlertmanagerConfig{
WorkingDirectory: filepath.Join(cfg.DataPath, workingDir, strconv.Itoa(int(orgID))),
ExternalURL: cfg.ParsedAppURL.String(), // LOGZ.IO GRAFANA CHANGE :: DEV-43657 - Set APP url to logzio grafana for alert notification URLs
ExternalURL: externalUrl, // LOGZ.IO GRAFANA CHANGE :: DEV-43657 - Set APP url to logzio grafana for alert notification URLs
AlertStoreCallback: nil,
PeerTimeout: cfg.UnifiedAlerting.HAPeerTimeout,
Silences: silencesOptions,
Expand Down
14 changes: 8 additions & 6 deletions pkg/services/ngalert/notifier/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ CommonAnnotations: {{ range .CommonAnnotations.SortedPairs }}{{ .Name }}={{ .Val
expected: TestTemplatesResults{
Results: []alertingNotify.TestTemplatesResult{{
Name: "slack.title",
Text: fmt.Sprintf("http://localhost:9093/d/%s?orgId=%s",
DefaultAnnotations[alertingModels.DashboardUIDAnnotation],
DefaultAnnotations[alertingModels.OrgIDAnnotation]),
// LOGZ.IO GRAFANA CHANGE :: DEV-45707: remove org id query param from notification urls
Text: fmt.Sprintf("http://localhost:9093/d/%s",
DefaultAnnotations[alertingModels.DashboardUIDAnnotation]),
// LOGZ.IO GRAFANA CHANGE :: End
}},
Errors: nil,
},
Expand All @@ -140,10 +141,11 @@ CommonAnnotations: {{ range .CommonAnnotations.SortedPairs }}{{ .Name }}={{ .Val
expected: TestTemplatesResults{
Results: []alertingNotify.TestTemplatesResult{{
Name: "slack.title",
Text: fmt.Sprintf("http://localhost:9093/d/%s?orgId=%s&viewPanel=%s",
// LOGZ.IO GRAFANA CHANGE :: DEV-45707: remove org id query param from notification urls
Text: fmt.Sprintf("http://localhost:9093/d/%s?viewPanel=%s",
DefaultAnnotations[alertingModels.DashboardUIDAnnotation],
DefaultAnnotations[alertingModels.OrgIDAnnotation],
DefaultAnnotations[alertingModels.PanelIDAnnotation]),
// LOGZ.IO GRAFANA CHANGE :: End
}},
Errors: nil,
},
Expand All @@ -157,7 +159,7 @@ CommonAnnotations: {{ range .CommonAnnotations.SortedPairs }}{{ .Name }}={{ .Val
expected: TestTemplatesResults{
Results: []alertingNotify.TestTemplatesResult{{
Name: "slack.title",
Text: fmt.Sprintf("http://localhost:3000?orgId=%s", DefaultAnnotations[alertingModels.OrgIDAnnotation]),
Text: "http://localhost:3000", // LOGZ.IO GRAFANA CHANGE :: DEV-45707: remove org id query param from notification urls
}},
Errors: nil,
},
Expand Down
Loading

0 comments on commit ada530d

Please sign in to comment.