Alerting: Return RuleResponse for api/prometheus/grafana/api/v1/rules (#32919)

* Return RuleResponse for api/prometheus/grafana/api/v1/rules

* change TODO to note

Co-authored-by: gotjosh <josue@grafana.com>

* pr feedback

* test fixup

Co-authored-by: gotjosh <josue@grafana.com>
This commit is contained in:
David Parrott
2021-04-13 14:38:09 -07:00
committed by GitHub
parent 50ab6155ff
commit 567a6a09bd
9 changed files with 147 additions and 23 deletions

View File

@@ -57,7 +57,7 @@ func (st *StateTracker) getOrCreate(uid string, orgId int64, result eval.Result)
st.stateCache.mu.Lock()
defer st.stateCache.mu.Unlock()
idString := fmt.Sprintf("%s %s", uid, result.Instance.String())
idString := fmt.Sprintf("%s %s", uid, map[string]string(result.Instance))
if state, ok := st.stateCache.cacheMap[idString]; ok {
return state
}

View File

@@ -18,6 +18,7 @@ func TestProcessEvalResults(t *testing.T) {
if err != nil {
t.Fatalf("error parsing date format: %s", err.Error())
}
cacheId := "test_uid map[label1:value1 label2:value2]"
testCases := []struct {
desc string
uid string
@@ -49,7 +50,7 @@ func TestProcessEvalResults(t *testing.T) {
{
UID: "test_uid",
OrgID: 123,
CacheId: "test_uid label1=value1, label2=value2",
CacheId: cacheId,
Labels: data.Labels{"label1": "value1", "label2": "value2"},
State: eval.Normal,
Results: []StateEvaluation{
@@ -87,7 +88,7 @@ func TestProcessEvalResults(t *testing.T) {
{
UID: "test_uid",
OrgID: 123,
CacheId: "test_uid label1=value1, label2=value2",
CacheId: cacheId,
Labels: data.Labels{"label1": "value1", "label2": "value2"},
State: eval.Alerting,
Results: []StateEvaluation{
@@ -126,7 +127,7 @@ func TestProcessEvalResults(t *testing.T) {
{
UID: "test_uid",
OrgID: 123,
CacheId: "test_uid label1=value1, label2=value2",
CacheId: cacheId,
Labels: data.Labels{"label1": "value1", "label2": "value2"},
State: eval.Normal,
Results: []StateEvaluation{
@@ -165,7 +166,7 @@ func TestProcessEvalResults(t *testing.T) {
{
UID: "test_uid",
OrgID: 123,
CacheId: "test_uid label1=value1, label2=value2",
CacheId: cacheId,
Labels: data.Labels{"label1": "value1", "label2": "value2"},
State: eval.Alerting,
Results: []StateEvaluation{
@@ -204,7 +205,7 @@ func TestProcessEvalResults(t *testing.T) {
{
UID: "test_uid",
OrgID: 123,
CacheId: "test_uid label1=value1, label2=value2",
CacheId: cacheId,
Labels: data.Labels{"label1": "value1", "label2": "value2"},
State: eval.Normal,
Results: []StateEvaluation{