Skip to content

Commit

Permalink
Adds continous metric to the deploytime
Browse files Browse the repository at this point in the history
Change that adds to the deploytime continous time series for the active
deployments.

Deployment with a timestamp creates an event, which may be in the past.
Having just an event we are unable to make calculations based on the
currently active deployments, because one may be gone from the cluster.

Adding deployment_active metric to already existing deploy_timestamp
will allow to better visualize Lead Time for Change, where the
"dots" are connected to each other, plus in the future we may be
able to answer additional questions such as how many deployed apps
are still working.

On top of that this change ensures one metric is presented
only one time in the series rather then multiple times. The metrics
were gathered several times multiplied by the number of found
unique deployments.

Signed-off-by: Michal Pryc <mpryc@redhat.com>

Clean up deploytime

- Simplifies reporting deploy_timestamp and deployment_active
- Simplifies DeployTimeMetric creation (datetime handling)

Signed-off-by: Kevin M Granger <kgranger@redhat.com>
Co-authored-by: Kevin M Granger <kgranger@redhat.com>
  • Loading branch information
mpryc and KevinMGranger committed Sep 21, 2022
1 parent 37cc199 commit 02855f7
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions exporters/deploytime/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,51 @@ def __init__(

def collect(self) -> Iterable[GaugeMetricFamily]:
logging.info("collect: start")
metric = GaugeMetricFamily(
"deploy_timestamp",
"Deployment timestamp",
labels=["namespace", "app", "image_sha"],
)

namespaces = self.get_and_log_namespaces()
if not namespaces:
return []

metrics = generate_metrics(namespaces, self.client)
# TODO: when merging 654, just ignore this whole section (overwrite with 654)
# all the code should be self-contained in the DeployTimeMetric anyway.

deploy_timestamp_metric = GaugeMetricFamily(
"deploy_timestamp",
"Deployment timestamp",
labels=["namespace", "app", "image_sha"],
)
deployment_active_metric = GaugeMetricFamily(
"deployment_active",
"Active deployments in cluster",
labels=["namespace", "app", "image_sha"],
)

for m in metrics:
logging.info(
"Collected deploy_timestamp{namespace=%s, app=%s, image=%s} %s"
% (
m.namespace,
m.name,
m.image_sha,
m.deploy_time_timestamp,
)
"Collected deploy_timestamp{namespace=%s, app=%s, image=%s} %s (%s)",
m.namespace,
m.name,
m.image_sha,
m.deploy_time_timestamp,
m.deploy_time,
)
metric.add_metric(
deploy_timestamp_metric.add_metric(
[m.namespace, m.name, m.image_sha],
m.deploy_time_timestamp,
timestamp=m.deploy_time_timestamp,
)
yield (metric)
logging.info(
"Collected deployment_active{namespace=%s, app=%s, image=%s} %s (%s)",
m.namespace,
m.name,
m.image_sha,
m.deploy_time_timestamp,
m.deploy_time,
)
deployment_active_metric.add_metric(
[m.namespace, m.name, m.image_sha],
m.deploy_time_timestamp,
)
return (deploy_timestamp_metric, deployment_active_metric)

def get_and_log_namespaces(self) -> set[str]:
"""
Expand Down

0 comments on commit 02855f7

Please sign in to comment.