anand
anand

Reputation: 301

Is there a NewRelic API to consume service levels (SLIs, SLOs)?

We have setup some SLIs and SLOs for some backend services using NewRelic Service levels. We want to consume those SLOs through an API to interrupt our Jenkins CI in case of SLO violations.

I have gone through NewRelic documentation but could only find APIs to create/edit service levels not to consume the values directly -

I also found this NerdGraph query to get the nrql for service levels created for an entity guid -

{
  actor {
    entity(guid: "{guid}") {
      serviceLevel {
        indicators {
          name
          id
          resultQueries {
            indicator {
              nrql
            }
          }
        }
      }
    }
  }
}

This generates the nrql but we want to consume the value directly through an API call. Is there an API or a way to do that? Basically to know if the 'x' days error budget is violated or not.

Upvotes: 0

Views: 189

Answers (1)

nobrac
nobrac

Reputation: 427

Service Level data is queryable with NRQL, and NRQL queries can be ran via GraphQL - I think you want something like this (as an example):

let q = 'FROM ServiceLevelSnapshot SELECT latest(remainingErrorBudget), latest(sliCompliance) where entity.name = '<your_service_level_name>' since 1 hour ago'

let gql = `{
  actor {
    account(id: <id>) {
      nrql(
        query: "{q}"
      ) {
        results
      }
    }
  }
}`

This would return the most recent error budget and compliance percentages- you can parse the results and fail the pipeline if needed.

Upvotes: 0

Related Questions