-
Notifications
You must be signed in to change notification settings - Fork 63
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
[Integration][New Relic] - Add support for service level #840
Changes from 8 commits
5f48f71
71fa389
a897f21
ee63e7c
2dcf84b
dd72146
b1ab418
e9a3753
dd1291b
fcc32ff
b7c8ab9
59f1146
ed04b60
418edbe
7982ea5
ff43d1c
903dd05
eff6699
926cf6c
6f405ee
cd57ac6
917a894
2065027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
GET_SLI_BY_NRQL_QUERY = """ | ||
{ | ||
actor { | ||
account(id: {{ account_id }}) { | ||
nrql(query: "{{ nrql_query }}") { | ||
results | ||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is that query is specific for SLI, can you add an example of the expected query that will be generated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "indicator":{
"nrql":"SELECT clamp_max((sum(newrelic.sli.valid) - sum(newrelic.sli.bad)) / sum(newrelic.sli.valid) * 100, 100) AS 'SLI' FROM Metric WHERE entity.guid = 'NDM2OTY4MHxFWFR8U0VSVklDRV9MRVZFTHw1OTk0MzM' UNTIL 2 minutes AGO"
} |
||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
LIST_SLOS_QUERY = """ | ||
{ | ||
actor { | ||
entitySearch(query: "type ='SERVICE_LEVEL'") { | ||
count | ||
query | ||
results{{ next_cursor_request }} { | ||
entities { | ||
serviceLevel { | ||
indicators { | ||
resultQueries { | ||
indicator { | ||
nrql | ||
} | ||
} | ||
id | ||
name | ||
description | ||
createdBy { | ||
} | ||
guid | ||
updatedAt | ||
createdAt | ||
updatedBy { | ||
} | ||
objectives { | ||
description | ||
target | ||
name | ||
timeWindow { | ||
rolling { | ||
count | ||
unit | ||
} | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
key | ||
values | ||
} | ||
} | ||
nextCursor | ||
} | ||
} | ||
} | ||
} | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from typing import Any, AsyncIterable, Tuple, Optional | ||
import httpx | ||
from port_ocean.context.ocean import ocean | ||
from newrelic_integration.core.query_templates.service_levels import ( | ||
LIST_SLOS_QUERY, | ||
GET_SLI_BY_NRQL_QUERY, | ||
) | ||
from newrelic_integration.core.utils import send_graph_api_request | ||
from newrelic_integration.utils import ( | ||
render_query, | ||
) | ||
from newrelic_integration.core.paging import send_paginated_graph_api_request | ||
|
||
SLI_OBJECT = "__SLI" | ||
|
||
|
||
class ServiceLevelsHandler: | ||
def __init__(self, http_client: httpx.AsyncClient): | ||
self.http_client = http_client | ||
|
||
async def get_service_level_indicator_value( | ||
self, http_client: httpx.AsyncClient, nrql: str | ||
) -> dict[Any, Any]: | ||
query = await render_query( | ||
GET_SLI_BY_NRQL_QUERY, | ||
nrql_query=nrql, | ||
account_id=ocean.integration_config.get("new_relic_account_id"), | ||
) | ||
response = await send_graph_api_request( | ||
http_client, query, request_type="get_service_level_indicator_value" | ||
) | ||
service_levels = ( | ||
response.get("data", {}) | ||
.get("actor", {}) | ||
.get("account", {}) | ||
.get("nrql", {}) | ||
.get("results", []) | ||
) | ||
if service_levels: | ||
return service_levels[0] | ||
return {} | ||
|
||
async def list_service_levels(self) -> AsyncIterable[dict[str, Any]]: | ||
|
||
async for service_level in send_paginated_graph_api_request( | ||
self.http_client, | ||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you look inside the |
||
LIST_SLOS_QUERY, | ||
request_type="list_service_levels", | ||
extract_data=self._extract_service_levels, | ||
): | ||
nrql = ( | ||
service_level.get("serviceLevel", {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment about that you are taking the |
||
.get("indicators", [])[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible that they will have more than one indicator and would want to have more than one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed this and it is not possible to have more than 1 |
||
.get("resultQueries", {}) | ||
.get("indicator", {}) | ||
.get("nrql") | ||
) | ||
service_level[SLI_OBJECT] = await self.get_service_level_indicator_value( | ||
self.http_client, nrql | ||
) | ||
self._format_tags(service_level) | ||
yield service_level | ||
|
||
@staticmethod | ||
async def _extract_service_levels( | ||
response: dict[Any, Any] | ||
) -> Tuple[Optional[str], list[dict[Any, Any]]]: | ||
"""Extract service levels from the response. used by send_paginated_graph_api_request""" | ||
results = ( | ||
response.get("data", {}) | ||
.get("actor", {}) | ||
.get("entitySearch", {}) | ||
.get("results", {}) | ||
) | ||
return results.get("nextCursor"), results.get("entities", []) | ||
|
||
@staticmethod | ||
def _format_tags(entity: dict[Any, Any]) -> dict[Any, Any]: | ||
entity["tags"] = {tag["key"]: tag["values"] for tag in entity.get("tags", [])} | ||
return entity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is repeating code we already have in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "newrelic" | ||
version = "0.1.61" | ||
version = "0.1.62" | ||
description = "New Relic Integration" | ||
authors = ["Tom Tankilevitch <[email protected]>"] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.