Skip to content

Commit

Permalink
Merge branch 'v10.4.x-logzio' into DEV-46410-Do-not-send-a-notificati…
Browse files Browse the repository at this point in the history
…on-on-error-or-no-data-state
  • Loading branch information
yasmin-tr committed Sep 18, 2024
2 parents 84f9c7a + 63db252 commit d476079
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/services/ngalert/accesscontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ var (
},
},
},
Grants: []string{string(org.RoleAdmin)},
Grants: []string{string(org.RoleEditor), string(org.RoleAdmin)}, // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
}

alertingProvisioningReaderWithSecretsRole = accesscontrol.RoleRegistration{
Expand Down
36 changes: 24 additions & 12 deletions pkg/tests/api/alerting/api_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor GET should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "editor", "")

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 200, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "admin", "")
Expand Down Expand Up @@ -148,15 +150,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor PUT should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor PUT should succeed", func(t *testing.T) {
req := createTestRequest("PUT", url, "editor", body)

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 202, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin PUT should succeed", func(t *testing.T) {
req := createTestRequest("PUT", url, "admin", body)
Expand Down Expand Up @@ -200,15 +204,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor GET should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "editor", "")

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 200, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "admin", "")
Expand Down Expand Up @@ -240,15 +246,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor POST should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor POST should succeed", func(t *testing.T) {
req := createTestRequest("POST", url, "editor", body)

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 202, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin POST should succeed", func(t *testing.T) {
req := createTestRequest("POST", url, "admin", body)
Expand Down Expand Up @@ -284,15 +292,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor GET should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "editor", "")

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 200, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "admin", "")
Expand Down Expand Up @@ -328,15 +338,17 @@ func TestIntegrationProvisioning(t *testing.T) {
require.Equal(t, 403, resp.StatusCode)
})

t.Run("editor GET should 403", func(t *testing.T) {
// LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning
t.Run("editor GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "editor", "")

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

require.Equal(t, 403, resp.StatusCode)
require.Equal(t, 200, resp.StatusCode)
})
// LOGZ.IO GRAFANA CHANGE :: End

t.Run("admin GET should succeed", func(t *testing.T) {
req := createTestRequest("GET", url, "admin", "")
Expand Down
8 changes: 8 additions & 0 deletions pkg/tsdb/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/grafana/grafana/pkg/models" // LOGZ.IO GRAFANA CHANGE :: DEV-43889 - Add headers for logzio datasources support
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -225,6 +226,13 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq

logger.Debug("Sending request to Elasticsearch", "resourcePath", req.Path)
start := time.Now()

// LOGZ.IO GRAFANA CHANGE :: DEV-43889 - Add headers for logzio datasources support
logzIoHeaders := &models.LogzIoHeaders{RequestHeaders: req.Headers}
request.Header = logzIoHeaders.GetDatasourceQueryHeaders(request.Header)
request.Header.Set("Content-Type", "application/json")
logger.Debug("request details", "headers", request.Header, "url", request.URL.String())
// LOGZ.IO GRAFANA CHANGE :: End
response, err := ds.HTTPClient.Do(request)
if err != nil {
status := "error"
Expand Down

0 comments on commit d476079

Please sign in to comment.