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

fixes possible error state in nautobot_ssot_duration_seconds metric #250

Merged
merged 1 commit into from
Oct 25, 2023
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
81 changes: 39 additions & 42 deletions nautobot_ssot/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,45 @@ def metric_ssot_jobs():
)

for job in Job.objects.all():
if issubclass(job.job_class, (DataSource, DataTarget)):
last_job_sync = Sync.objects.filter(job_result__job_model_id=job.id).last()
if last_job_sync:
if last_job_sync.source_load_time:
ssot_job_durations.add_metric(
labels=["source_load_time", ".".join(job.natural_key())],
value=(
(last_job_sync.source_load_time.seconds * 100000)
+ last_job_sync.source_load_time.microseconds
)
/ 1000,
)

if last_job_sync.target_load_time:
ssot_job_durations.add_metric(
labels=["target_load_time", ".".join(job.natural_key())],
value=(
(last_job_sync.target_load_time.seconds * 1000000)
+ last_job_sync.target_load_time.microseconds
)
/ 1000,
)

if last_job_sync.diff_time:
ssot_job_durations.add_metric(
labels=["diff_time", ".".join(job.natural_key())],
value=((last_job_sync.diff_time.seconds * 1000000) + last_job_sync.diff_time.microseconds)
/ 1000,
)

if last_job_sync.sync_time:
ssot_job_durations.add_metric(
labels=["sync_time", ".".join(job.natural_key())],
value=((last_job_sync.sync_time.seconds * 1000000) + last_job_sync.sync_time.microseconds)
/ 1000,
)

if last_job_sync.duration:
ssot_job_durations.add_metric(
labels=["sync_duration", ".".join(job.natural_key())],
value=((last_job_sync.duration.seconds * 1000000) + last_job_sync.duration.microseconds) / 1000,
)
# Skip any jobs that aren't SSoT jobs
if job.job_class is None or not issubclass(job.job_class, (DataSource, DataTarget)):
continue

last_job_sync = Sync.objects.filter(job_result__job_model_id=job.id).last()
if not last_job_sync:
continue

if last_job_sync.source_load_time:
ssot_job_durations.add_metric(
labels=["source_load_time", ".".join(job.natural_key())],
value=((last_job_sync.source_load_time.seconds * 100000) + last_job_sync.source_load_time.microseconds)
/ 1000,
)

if last_job_sync.target_load_time:
ssot_job_durations.add_metric(
labels=["target_load_time", ".".join(job.natural_key())],
value=((last_job_sync.target_load_time.seconds * 1000000) + last_job_sync.target_load_time.microseconds)
/ 1000,
)

if last_job_sync.diff_time:
ssot_job_durations.add_metric(
labels=["diff_time", ".".join(job.natural_key())],
value=((last_job_sync.diff_time.seconds * 1000000) + last_job_sync.diff_time.microseconds) / 1000,
)

if last_job_sync.sync_time:
ssot_job_durations.add_metric(
labels=["sync_time", ".".join(job.natural_key())],
value=((last_job_sync.sync_time.seconds * 1000000) + last_job_sync.sync_time.microseconds) / 1000,
)

if last_job_sync.duration:
ssot_job_durations.add_metric(
labels=["sync_duration", ".".join(job.natural_key())],
value=((last_job_sync.duration.seconds * 1000000) + last_job_sync.duration.microseconds) / 1000,
)

yield ssot_job_durations

Expand Down