-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy
cortex/pkg/configs
package dependency into Loki (#5139)
* Fork cortex `configs` into Loki. * Use new forked `configs` package. * Remove duplicated import. * Fix lint issues. * Use new forked util/logger. * Drop support for promql rules v1. - This allow us to remove the `legacy_promql` implementation - If a rulesconfig is received in v1 format, we output a specific error, so we can differentiate between a unknown version and a v1 one. * Modify tests to expect error for legacy rules format. * Add changelog and upgrading guide. - Added them as we dropped support for legacy promql rules configuration which might be a breaking change for some environments. * Update vendor/modules after rebasing.
- Loading branch information
1 parent
4a70f8e
commit 3d135e5
Showing
21 changed files
with
354 additions
and
6,891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package client | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/grafana/loki/pkg/configs/userconfig" | ||
) | ||
|
||
var response = `{ | ||
"configs": { | ||
"2": { | ||
"id": 1, | ||
"config": { | ||
"rules_files": { | ||
"recording.rules": "groups:\n- name: demo-service-alerts\n interval: 15s\n rules:\n - alert: SomethingIsUp\n expr: up == 1\n" | ||
}, | ||
"rule_format_version": "2" | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
func TestDoRequest(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
_, err := w.Write([]byte(response)) | ||
require.NoError(t, err) | ||
})) | ||
defer server.Close() | ||
|
||
resp, err := doRequest(server.URL, 1*time.Second, nil, 0) | ||
assert.Nil(t, err) | ||
|
||
expected := ConfigsResponse{Configs: map[string]userconfig.View{ | ||
"2": { | ||
ID: 1, | ||
Config: userconfig.Config{ | ||
RulesConfig: userconfig.RulesConfig{ | ||
Files: map[string]string{ | ||
"recording.rules": "groups:\n- name: demo-service-alerts\n interval: 15s\n rules:\n - alert: SomethingIsUp\n expr: up == 1\n", | ||
}, | ||
FormatVersion: userconfig.RuleFormatV2, | ||
}, | ||
}, | ||
}, | ||
}} | ||
assert.Equal(t, &expected, resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.