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

fix(provider): gcpmonitoring logs default severity #2393

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
23 changes: 21 additions & 2 deletions keep/providers/gcpmonitoring_provider/gcpmonitoring_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class LogEntry(pydantic.BaseModel):
payload_exists: bool = False
http_request_exists: bool = False

@pydantic.validator("severity", pre=True)
def validate_severity(cls, severity):
if severity is None:
return "INFO"
return severity


@pydantic.dataclasses.dataclass
class GcpmonitoringProviderAuthConfig:
Expand Down Expand Up @@ -131,7 +137,13 @@ def __generate_client(self) -> google.cloud.logging.Client:
return self._client

def _query(
self, filter: str, timedelta_in_days=1, page_size=1000, raw="true", **kwargs
self,
filter: str,
timedelta_in_days=1,
page_size=1000,
raw="true",
project="",
**kwargs,
):
raw = raw == "true"
self.logger.info(
Expand All @@ -143,6 +155,10 @@ def _query(
- datetime.timedelta(days=timedelta_in_days)
).strftime("%Y-%m-%dT%H:%M:%SZ")
filter = f'{filter} timestamp>="{start_time}"'

if project:
self.client.project = project

entries_iterator = self.client.list_entries(filter_=filter, page_size=page_size)
entries = []
for entry in entries_iterator:
Expand Down Expand Up @@ -252,5 +268,8 @@ def _format_alert(
provider_type="gcpmonitoring",
provider_config=config,
)
entries = provider._query(filter='resource.type = "cloud_run_revision"')
entries = provider._query(
filter='resource.type = "cloud_run_revision"',
raw=False,
)
print(entries)
Loading