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

Add pagination to Monte Carlo getMonitors call #1050

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions metaphor/monte_carlo/extractor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import traceback
from typing import Collection, Dict, List

from dateutil import parser
Expand Down Expand Up @@ -102,11 +101,15 @@
See https://apidocs.getmontecarlo.com/#query-getMonitors
"""

try:
monitors = self._client(
offset = 0
limit = 200
mars-lan marked this conversation as resolved.
Show resolved Hide resolved

monitors = []
while True:
resp = self._client(
"""
{
getMonitors {
query getMonitors($offset: Int, $limit: Int) {
getMonitors(offset: $offset, limit: $limit) {
uuid
name
description
Expand All @@ -120,16 +123,20 @@
exceptions
}
}
"""
""",
{"offset": offset, "limit": limit},
)

logger.info(f"Fetched {len(monitors['get_monitors'])} monitors")
json_dump_to_debug_file(monitors, "getMonitors.json")
logger.info(f"Querying getMonitors with offset {offset}")
monitors.extend(resp["get_monitors"])
if len(resp["get_monitors"]) < limit:
break

offset += limit

Check warning on line 135 in metaphor/monte_carlo/extractor.py

View check run for this annotation

Codecov / codecov/patch

metaphor/monte_carlo/extractor.py#L135

Added line #L135 was not covered by tests

self._parse_monitors(monitors)
except Exception as error:
traceback.print_exc()
logger.error(f"Failed to get all monitors, error {error}")
logger.info(f"Fetched {len(monitors)} monitors")
json_dump_to_debug_file(monitors, "getMonitors.json")
self._parse_monitors(monitors)

def _fetch_tables(self) -> None:
"""Fetch all tables
Expand Down Expand Up @@ -188,7 +195,7 @@
self._mcon_platform_map[mcon] = platform

def _parse_monitors(self, monitors) -> None:
for monitor in monitors["get_monitors"]:
for monitor in monitors:
uuid = monitor["uuid"]
monitor_severity = monitor_severity_map.get(
monitor["priority"], DataMonitorSeverity.UNKNOWN
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.14.161"
version = "0.14.162"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down
Loading