Insight logs format fixes (#1763)
# What this PR does Minot fixes of insight logs formatting
This commit is contained in:
parent
75824dc9ad
commit
15e7baad88
4 changed files with 9 additions and 9 deletions
|
|
@ -9,8 +9,8 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class ChatOpsEvent(enum.Enum):
|
||||
WORKSPACE_CONNECTED = "started"
|
||||
WORKSPACE_DISCONNECTED = "finished"
|
||||
WORKSPACE_CONNECTED = "workspace_connected"
|
||||
WORKSPACE_DISCONNECTED = "workspace_disconnected"
|
||||
CHANNEL_CONNECTED = "channel_connected"
|
||||
CHANNEL_DISCONNECTED = "channel_disconnected"
|
||||
USER_LINKED = "user_linked"
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ logger = logging.getLogger(__name__)
|
|||
def is_insight_logs_enabled(organization):
|
||||
"""
|
||||
is_insight_logs_enabled checks if inside logs enabled for given organization.
|
||||
Now it checks if oncall is deployed on same cluster that its grafana instance to be able to forward logs.
|
||||
Or if it's Open Source :)
|
||||
Now it checks if oncall is deployed on same cluster that its grafana instance to be able to forward logs
|
||||
to Loki through logs-forwarder.
|
||||
"""
|
||||
logger.info(
|
||||
"is_insight_logs_enabled: "
|
||||
|
|
@ -17,4 +17,4 @@ def is_insight_logs_enabled(organization):
|
|||
f"ONCALL_BACKEND_REGION={settings.ONCALL_BACKEND_REGION} "
|
||||
f"cluster_slug={organization.cluster_slug}"
|
||||
)
|
||||
return settings.IS_OPEN_SOURCE or settings.ONCALL_BACKEND_REGION == organization.cluster_slug
|
||||
return not settings.IS_OPEN_SOURCE and settings.ONCALL_BACKEND_REGION == organization.cluster_slug
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def write_maintenance_insight_log(instance, user, event: MaintenanceEvent):
|
|||
team = instance.get_team()
|
||||
entity_name = json.dumps(instance.insight_logs_verbal)
|
||||
entity_id = instance.public_primary_key
|
||||
maintenance_mode = instance.get_maintenance_mode_display()
|
||||
maintenance_mode = instance.get_maintenance_mode_display().lower()
|
||||
|
||||
if is_insight_logs_enabled(organization):
|
||||
log_line = f"tenant_id={tenant_id} action_type=maintenance action_name={event.value} maintenance_mode={maintenance_mode} resource_id={entity_id} resource_name={entity_name}" # noqa
|
||||
|
|
@ -32,7 +32,7 @@ def write_maintenance_insight_log(instance, user, event: MaintenanceEvent):
|
|||
if user:
|
||||
username = json.dumps(user.username)
|
||||
user_id = user.public_primary_key
|
||||
log_line += f" user_id={user_id} username={username} "
|
||||
log_line += f" author_id={user_id} author={username}"
|
||||
insight_logger.info(log_line)
|
||||
except Exception as e:
|
||||
logger.warning(f"insight_log.failed_to_write_maintenance_insight_log exception={e}")
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ def write_resource_insight_log(instance: InsightLoggable, author, event: EntityE
|
|||
entity_id = instance.id
|
||||
entity_name = json.dumps(instance.insight_logs_verbal)
|
||||
metadata = instance.insight_logs_metadata
|
||||
log_line = f"tenant_id={tenant_id} author_id={author_id} author={author} action_type=resource action={event.value} resource_type={entity_type} resource_id={entity_id} resource_name={entity_name}" # noqa
|
||||
log_line = f"tenant_id={tenant_id} author_id={author_id} author={author} action_type=resource action_name={event.value} resource_type={entity_type} resource_id={entity_id} resource_name={entity_name}" # noqa
|
||||
for k, v in metadata.items():
|
||||
log_line += f" {k}={json.dumps(v)}"
|
||||
if prev_state and new_state:
|
||||
|
|
@ -82,7 +82,7 @@ def write_resource_insight_log(instance: InsightLoggable, author, event: EntityE
|
|||
log_line += f' new_state="{new_state}"'
|
||||
insight_logger.info(log_line)
|
||||
except Exception as e:
|
||||
logger.warning(f"insight_log.failed_to_write_entity_insight_log exception={e}")
|
||||
logger.warning(f"insight_log.failed_to_write_entity_insight_log exception={e} instance_id={instance.id}")
|
||||
|
||||
|
||||
def state_diff_finder(prev_state: dict, new_state: dict):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue