Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules v1 API #3656

Closed
wants to merge 3 commits into from
Closed

Rules v1 API #3656

wants to merge 3 commits into from

Conversation

midnightconman
Copy link

This is part of #2467

Jon Campbell and others added 2 commits January 4, 2018 16:17
@brian-brazil
Copy link
Contributor

Can you share example output?

@midnightconman
Copy link
Author

Sure 😄

I added all strings, group name and file, and rules (yaml).

{
  "status": "success",
  "data": {
    "groups": [
      {
        "name": "general.rules",
        "file": "rules.yaml",
        "rules": [
          {
            "rule": "alert: DeadMansSwitch\nexpr: vector(1)\nlabels:\n  severity: none\nannotations:\n  description: This is a DeadMansSwitch meant to ensure that the entire Alerting pipeline
\n    is functional.\n  summary: Alerting DeadMansSwitch\n"
          }
        ]
      },
      {
        "name": "general2.rules",
        "file": "rules2.yaml",
        "rules": [
          {
            "rule": "alert: DeadMansSwitch2\nexpr: vector(1)\nlabels:\n  severity: none\nannotations:\n  description: This is a DeadMansSwitch meant to ensure that the entire Alerting pipelin
e\n    is functional.\n  summary: Alerting DeadMansSwitch\n"
          }
        ]
      }
    ]
  }
}

@moolitayer
Copy link

moolitayer commented Jan 8, 2018

Parsing the JSON and YAML mixture could be complex.
Would it make sense to convert the rules to JSON here?

@brian-brazil
Copy link
Contributor

I think a structure more like #3391 would make more sense. Returning YAML should be for entire files (so someday we can include comments too for the main config), it isn't needed in more detailed views.

@midnightconman
Copy link
Author

@brian-brazil can you be more specific on the format changes? I don't see a difference between #3391 rules api and this output.

{
  "status": "success",
  "data": {
    "groups": [
      {
        "name": "rule_grp2",
        "file": "/home/user/allrules/grp2_rules.yml",
        "rules": [
          {
            "rule": "alert: R1file2\nexpr: up != 2\nfor: 10s\nlabels:\n  env: test\n  severity: high\nannotations:\n  dashboard: http://grafana.com/somelink\n  description: rule1 in file 2\n  summary: rule1 in file 2\n"
          }
        ]
      },
      {
        "name": "grp3",
        "file": "/home/user/allrules/grp3_rules.yml",
        "rules": [
          {
            "rule": "record: instance:errors:rate5m\nexpr: rate(errors_total[5m])\n"
          },
          {
            "rule": "record: instance:requests:rate5m\nexpr: rate(requests_total[5m])\n"
          },
          {
            "rule": "alert: HighErrors\nexpr: (100 - (avg(irate(node_cpu{mode=\"idle\",name=\"node-exporter\"}[5m])) BY (instance)\n  * 100)) > 75\nfor: 5m\nlabels:\n  severity: critical\nannotations:\n  description: '{{$labels.instance}}:CPU usage is above 75% (current value is:{{ $value\n    }})'\n"
          }
        ]
      },
      {
        "name": "rule_grp1",
        "file": "/home/user/allrules/grp1_rules.yml",
        "rules": [
          {
            "rule": "alert: R1file1\nexpr: up{job=\"prometheus\"} == 1\nfor: 2m\nlabels:\n  env: prod\n  severity: high\nannotations:\n  dashboard: http://grafana.com/somelink\n  description: rule1 in file 1\n  summary: rule1 in file 1\n"
          },
          {
            "rule": "alert: R2file1\nexpr: up{job=\"prom\"} == 0\nfor: 2m\nlabels:\n  env: prod\n  severity: critical\nannotations:\n  dashboard: http://grafana.com/somelink\n  description: rule2 in file 1\n  summary: rule2 in file 1\n"
          }
        ]
      }
    ]
  }
}

@midnightconman
Copy link
Author

@moolitayer there were concerns about format and field changes, so the original request was for a string return. We could convert this yaml to json, but it probably shouldn't be here. We could return json from rules.go as a new method?

@moolitayer
Copy link

@midnightconman I wasn't aware of any backward compatibility concerns, can you elaborate on that a little? It would be helpful to think of how in the future we could request a different output format from the API if we need to implement something different.

BTW are there any plans for rule mutating API? (and how would that work with rule configuration files)

We could return json from rules.go as a new method?

How would that be exposed?

@brian-brazil
Copy link
Contributor

I don't see a difference between #3391 rules api and this output.

#3391 breaks out the fields of the rule.

BTW are there any plans for rule mutating API?

There aren't.

@midnightconman
Copy link
Author

midnightconman commented Jan 9, 2018

Do we wan't this to be schema-full or schema-less? Meaning, do we only want to provide the fields in the current struct and new fields would be dropped?

Also, do we want to do this if it requires existing struct changes? Here is the existing Rule struct: https://github.com/prometheus/prometheus/blob/master/rules/manager.go#L135

@brian-brazil
Copy link
Contributor

If/when there's new fields the code can be changed.

@simonpasquier
Copy link
Member

@midnightconman are you still working on this?

@ranjithkumar-s
Copy link

@midnightconman
Hey I tried to get the list of rules in prometheus via API but i got only Method Not Allowed error
curl -X GET http://192.168.10.101:9090/api/v1/rules

And also i want to create a rule via API. Is that possible?

@mxinden mxinden mentioned this pull request Jun 18, 2018
@mxinden
Copy link
Member

mxinden commented Aug 13, 2018

With #4318 merged, I am closing here. Let me know if I am missing something.

@mxinden mxinden closed this Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants