Parca

  • Canonical Observability
Channel Revision Published Runs on
latest/stable 128 14 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
latest/beta 137 29 Feb 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 154 29 Jul 2024
Ubuntu 22.04 Ubuntu 20.04
juju deploy parca
Show information

Platform:

Ubuntu
22.04 20.04

charms.parca.v0.parca_store

Overview.

This document explains how to integrate with the Parca charm where you wish to use Parca as a store for profiles that are sent from a Parca Agent.

Requirer Library usage

In this mode, your charm will be an application that needs to receive store configuration over the relation in order that the workload can be configured to use a remote store for profiles.

To begin, start by importing the library and subscribing to some events:

from charms.parca.v0.parca_store import (ParcaStoreEndpointRequirer, RemoveStoreEvent)

def __init__(self, *args):
    super().__init__(*args)
    # ...
    self.store_requirer = ParcaStoreEndpointRequirer(
        self, relation_name="external-parca-store-endpoint"
    )
    self.framework.observe(self.store_requirer.on.endpoints_changed, self._configure_store)
    self.framework.observe(self.store_requirer.on.remove_store, self._configure_store)
    # ...

def _configure_store(self, event):
    store_config = {} if isinstance(event, RemoveStoreEvent) else event.store_config
    self.application.configure(store_config=store_config)
    # ...

You can also fetch the store config at any time by using self.store_requirer.config.

Provider library usage

In this mode, your charm will be the charm that provides the store capability. In order to use the library, you must first import it, and initialise it in your charm's constructor:

from charms.parca.v0.parca_store import ParcaStoreEndpointProvider

def __init__(self, *args):
    super().__init__(*args)
    # ...
    self.parca_store_endpoint = ParcaStoreEndpointProvider(
        charm = self,
        port = 7070,
        insecure = True
    )
    # ...

This will ensure that any client wishing to send profiles will be sent the application address, along with the instruction to not use TLS for the connection.

If your store integrates with an ingress (such as Traefik), you will also need to pass the external_url parameter:

from charms.parca.v0.parca_store import ParcaStoreEndpointProvider

def __init__(self, *args):
    super().__init__(*args)
    # ...
    self.parca_store_endpoint = ParcaStoreEndpointProvider(
        charm = self,
        external_url = self._external_url(),
        port = 443,
        insecure = False
    )
    # ...

If your Parca store requires authentication with a bearer token, you can provide a method that can be called for generating tokens on a per-relation basis:

from charms.parca.v0.parca_store import ParcaStoreEndpointProvider

def __init__(self, *args):
    super().__init__(*args)
    # ...
    self.parca_store_endpoint = ParcaStoreEndpointProvider(
        charm = self,
        token_generator = self._bearer_token_generator
    )
    # ...

Where self._bearer_token_generator can be any Callable that returns a string.


class ParcaStoreEndpointProvider

Description

Profiling endpoint for Parca. None

Methods

ParcaStoreEndpointProvider. __init__( self , charm , port: int , insecure: bool , external_url: str , token_generator: Callable , relation_name: str )

Construct a Parca profile store provider.

Arguments

charm

a ops.CharmBase object that manages this ParcaStoreEndpointProvider object. Typically this is self in the instantiating class.

port

an optional integer that represents the port on which the Parca Store listens.

insecure

an optional boolean that instructs clients whether or not to use TLS when connecting to the endpoint provided. Defaults to False, implying that by default TLS should be used.

external_url

an optional string that represents the URL at which the Parca Store endpoint can be reached. Useful when the Parca Store implementation is behind an ingress or reverse proxy.

token_generator

an optional method or lambda that can generate valid bearer tokens for the Parca Store. Defaults to a lambda that returns an empty string.

relation_name

an optional string that denotes the name of the relation endpoint.

Description

If your charm exposes a Parca Store endpoint, the ParcaStoreEndpointProvider object enables your charm to easily communicate how to reach that endpoint.

class StoreEndpointsChangedEvent

Description

Event emitted when Parca store endpoints change. None

Methods

StoreEndpointsChangedEvent. __init__( self , handle , relation_id , remote_store_address , remote_store_bearer_token , remote_store_insecure )

StoreEndpointsChangedEvent. snapshot( self )

Description

Save store relation information. None

StoreEndpointsChangedEvent. restore( self , snapshot )

Description

Restore store relation information. None

class RemoveStoreEvent

Description

Event emitted when Parca store config should be removed. None

Methods

RemoveStoreEvent. __init__( self , handle , relation_id )

RemoveStoreEvent. snapshot( self )

Description

Save store relation information. None

RemoveStoreEvent. restore( self , snapshot )

Description

Restore store relation information. None

class ParcaStoreEvents

Description

Event descriptor for events raised by ParcaStoreEndpointRequirer. None

class ParcaStoreEndpointRequirer

Description

Provide an interface for apps that need to send data to a Parca Store. None

Methods

ParcaStoreEndpointRequirer. __init__( self , charm , relation_name: str )

Construct a Parca profile store requirer.

Arguments

charm

a ops.CharmBase object that manages this ParcaStoreEndpointRequirer object. Typically this is self in the instantiating class.

relation_name

an optional string that denotes the name of the relation endpoint.

ParcaStoreEndpointRequirer. config( self )

Description

Return the store config for a given requirer if the relation is formed. None