-
Notifications
You must be signed in to change notification settings - Fork 61
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
[Core] Add metrics for ocean core #1260
base: main
Are you sure you want to change the base?
[Core] Add metrics for ocean core #1260
Conversation
1. Add classes to encapsulate metrics data. 2. Add class to encapsulate metric modification. 3. Add Metric event into `event.py`. 4. Add metric helper decorator to provide context with phase and measure time. 5. Add metric wrapper for async generators to measure time. 6. Add increment metric calls to measure stats. 7. Add tests to validate how many entities were extraced and processed. 8. Add test to compare performance of two branches.
Refactor increment methods.
Set metrics as feature flag.
69bb09b
to
daf9cf0
Compare
Remove perf tests results
1. Fix `validate_metrics`. 2. Pass Metric env to tests.
Add metrics to topological sorter
@@ -72,6 +75,8 @@ async def upsert_entity( | |||
extensions={"retryable": True}, | |||
) | |||
if response.is_error: | |||
await event.event.increment_metric(MetricFieldType.ERROR_COUNT) |
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.
await event.event.increment_metric(MetricFieldType.ERROR_COUNT) | |
await event.event.increment_metric(MetricFieldType.PORT_API_ERROR_COUNT) |
|
||
return reduced_entity | ||
|
||
@metric(MetricType.LOAD) |
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.
shouldn't it be on top of the upsert_entity
method rather than batch_upsert_entities
?
@@ -167,6 +178,7 @@ async def delete_entity( | |||
) | |||
|
|||
if response.is_error: | |||
await event.event.increment_metric(MetricFieldType.ERROR_COUNT) |
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.
should this kind of error count be in the upsert_entity
as well?
@@ -79,6 +79,7 @@ class IntegrationConfiguration(BaseOceanSettings, extra=Extra.allow): | |||
) | |||
runtime: Runtime = Runtime.OnPrem | |||
resources_path: str = Field(default=".port/resources") | |||
metrics: bool = Field(default=False) |
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.
I would suggest to have the type as some kind of enum for cases where it won't be only true
or false
but rather might want to only monitor extract metrics
port_ocean/helpers/metric.py
Outdated
break | ||
|
||
|
||
def metric(phase: str | None = None, should_capture_time: bool = True) -> Any: |
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.
add docs
port_ocean/tests/test_metric.py
Outdated
assert metrics, "No 'metrics' key found in the parsed JSON." | ||
|
||
assert "fake-person" in metrics, "'fake-person' key missing in metrics data." | ||
fake_person = metrics["fake-person"] |
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.
what fake-person
mean in a metric? I understand that its contains the extract
, load
transform
but I wonder how we can monitor that?
port_ocean/context/event.py
Outdated
@@ -163,6 +203,7 @@ def _handle_event(triggering_event_id: int) -> None: | |||
dispatcher.connect(_handle_event, event_type) | |||
dispatcher.send(event_type, triggering_event_id=event.id) | |||
|
|||
is_silent = EventType.METRIC == event_type |
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.
why this is needed for?
port_ocean/helpers/metric.py
Outdated
except Exception: | ||
break |
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.
why break
? how the exception
is being propogated? its not equivalent to the way you are iterating over when if not port_ocean.context.event.event.should_record_metrics
port_ocean/helpers/metric.py
Outdated
async def increment_status(self, status_code: str) -> None: | ||
metric = await self.get_metric() | ||
if metric is None or not isinstance(metric, ApiStats): | ||
return None | ||
async with self._lock: | ||
|
||
status = metric.requests.get(status_code) | ||
if not status: | ||
metric.requests[status_code] = 0 | ||
metric.requests[status_code] = metric.requests.get(status_code, 0) + 1 |
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.
I wonder if this is actually needed 🤔 its sounds too specific, you already implemented increment_field
port_ocean/helpers/metric.py
Outdated
async def flush(self) -> None: | ||
async with self._lock: | ||
metric_dict = asdict(self.metrics) | ||
logger.info(f"integration metrics {json.dumps(metric_dict)}") |
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.
please share in the pr description the flush
output
convert metrics to use prometheus
increment_field
method for handling counters.increment_status
method for handling requests.MetricAggregator
to track metrics.Type of change
Please leave one option from the following and delete the rest:
All tests should be run against the port production environment(using a testing org).
Core testing checklist
Integration testing checklist
examples
folder in the integration directory.Preflight checklist
Screenshots
Include screenshots from your environment showing how the resources of the integration will look.
API Documentation
Provide links to the API documentation used for this integration.