Observability Libs
- By Jon Seager
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/edge | 12 | 22 May 2023 |
juju deploy observability-libs --channel edge
You will need Juju 2.9 to be able to run this command. Learn how to upgrade to Juju 2.9.
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
charms.observability_libs.v0.juju_topology
-
- Last updated 01 Mar 2023
- Revision Library version 0
Overview.
This document explains how to use the JujuTopology
class to
create and consume topology information from Juju in a consistent manner.
The goal of the Juju topology is to uniquely identify a piece of software running across any of your Juju-managed deployments. This is achieved by combining the following four elements:
- Model name
- Model UUID
- Application name
- Unit identifier
For a more in-depth description of the concept, as well as a walk-through of it's use-case in observability, see this blog post on the Juju blog.
Library Usage
This library may be used to create and consume JujuTopology
objects.
The JujuTopology
class provides three ways to create instances:
Using the from_charm
method
Enables instantiation by supplying the charm as an argument. When creating topology objects for the current charm, this is the recommended approach.
topology = JujuTopology.from_charm(self)
Using the from_dict
method
Allows for instantion using a dictionary of relation data, like the
scrape_metadata
from Prometheus or the labels of an alert rule. When
creating topology objects for remote charms, this is the recommended
approach.
scrape_metadata = json.loads(relation.data[relation.app].get("scrape_metadata", "{}"))
topology = JujuTopology.from_dict(scrape_metadata)
Using the class constructor
Enables instantiation using whatever values you want. While this is useful in some very specific cases, this is almost certainly not what you are looking for as setting these values manually may result in observability metrics which do not uniquely identify a charm in order to provide accurate usage reporting, alerting, horizontal scaling, or other use cases.
topology = JujuTopology(
model="some-juju-model",
model_uuid="00000000-0000-0000-0000-000000000001",
application="fancy-juju-application",
unit="fancy-juju-application/0",
charm_name="fancy-juju-application-k8s",
)
Index
class InvalidUUIDError
Description
Invalid UUID was provided. None
Methods
InvalidUUIDError. __init__( self , uuid: str )
class JujuTopology
JujuTopology is used for storing, generating and formatting juju topology information.
Description
DEPRECATED: This class is deprecated. Use `pip install cosl` and `from cosl.juju_topology import JujuTopology` instead.
Methods
JujuTopology. __init__( self , model: str , model_uuid: str , application: str , unit , charm_name )
Build a JujuTopology object.
Arguments
Description
JujuTopology. is_valid_uuid( self , uuid )
Validate the supplied UUID against the Juju Model UUID pattern.
Arguments
Returns
JujuTopology. from_charm( cls , charm )
Creates a JujuTopology instance by using the model data available on a charm object.
Arguments
Returns
JujuTopology. from_dict( cls , data: dict )
Factory method for creating `JujuTopology` children from a dictionary.
Arguments
Returns
JujuTopology. as_dict( self )
Format the topology information into an ordered dict.
Arguments
Description
JujuTopology. identifier( self )
Format the topology information into a terse string.
Description
JujuTopology. label_matcher_dict( self )
Format the topology information into a dict with keys having 'juju_' as prefix.
Description
JujuTopology. label_matchers( self )
Format the topology information into a promql/logql label matcher string.
Description
JujuTopology. model( self )
Description
JujuTopology. model_uuid( self )
Description
JujuTopology. model_uuid_short( self )
Description
JujuTopology. application( self )
Description
JujuTopology. charm_name( self )
Description
JujuTopology. unit( self )
Description