Skip to content

Commit

Permalink
move work from tempo-k8s@tempo-coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Jun 19, 2024
1 parent c44df77 commit 5931889
Show file tree
Hide file tree
Showing 86 changed files with 15,353 additions and 1,082 deletions.
43 changes: 35 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Contributing

To make contributions to this charm, you'll need a working [development setup](https://juju.is/docs/sdk/dev-setup).
## Overview

This documents explains the processes and practices recommended for contributing enhancements to
this operator.

- Generally, before developing enhancements to this charm, you should consider [opening an issue
](https://github.com/jnsgruk/zinc-k8s-operator/issues) explaining your use case.
- If you would like to chat with us about your use-cases or proposed implementation, you can reach
us at [Canonical Mattermost public channel](https://chat.charmhub.io/charmhub/channels/charm-dev)
or [Discourse](https://discourse.charmhub.io/).
- Familiarising yourself with the [Charmed Operator Framework](https://juju.is/docs/sdk) library
will help you a lot when working on new features or bug fixes.
- All enhancements require review before being merged. Code review typically examines
- code quality
- test coverage
- user experience for Juju administrators this charm.
- Please help us out in ensuring easy to review branches by rebasing your pull request branch onto
the `main` branch. This also avoids merge commits and creates a linear Git commit history.

## Developing

You can use the environments created by `tox` for development:

Expand All @@ -9,25 +28,33 @@ tox --notest -e unit
source .tox/unit/bin/activate
```

## Testing

This project uses `tox` for managing test environments. There are some pre-configured environments
that can be used for linting and formatting code when you're preparing contributions to the charm:
### Testing

```shell
tox -e fmt # update your code according to linting rules
tox -e lint # code style
tox -e unit # unit tests
tox -e scenario # scenario tests
tox -e integration # integration tests
tox # runs 'lint' and 'unit' environments
tox # runs 'lint', 'scenario' and 'unit' environments
```

## Build the charm
## Build charm

Build the charm in this git repository using:

```shell
charmcraft pack
```

<!-- You may want to include any contribution/style guidelines in this document>
### Deploy

```bash
# Create a model
juju add-model dev
# Enable DEBUG logging
juju model-config logging-config="<root>=INFO;unit=DEBUG"
# Deploy the charm
juju deploy ./zinc-k8s_ubuntu-20.04-amd64.charm \
--resource zinc-image=public.ecr.aws/m5j1b6u0/zinc:v0.1.1 \
```
47 changes: 47 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Deploying Tempo

To manually test and develop tempo:

charmcraft pack
charmcraft pack -p ./tests/integration/tester/
j deploy ./tempo-k8s_ubuntu-22.04-amd64.charm tempo --resource tempo-image=grafana/tempo:2.4.0

you need to always deploy at least 2 units of tester:

j deploy ./tester_ubuntu-22.04-amd64.charm tester -n 3 --resource workload=python:slim-buster
j relate tempo:tracing tester:tracing

# Object storage

In order to test tempo with object storage (using [minio charm](https://github.com/canonical/minio-operator)),
you can do the following (replace YOUR_MINIO_ACCESS_KEY and YOUR_MINIO_SECRET with anything you want as long as the
secret is more than 8 characters):

Deploy minio:
```
juju deploy minio --channel edge --trust
juju config minio access-key=YOUR_MINIO_ACCESS_KEY
juju config minio secret-key=YOUR_MINIO_SECRET
```

Deploy mc and set up buckets:
```
sudo snap install minio-client --edge --devmode
kubectl port-forward service/minio -n test-minio 9000:9000
minio-client config host add local http://localhost:9000 YOUR_MINIO_ACCESS_KEY YOUR_MINIO_SECRET
minio-client mb local/tempo
```

Deploy and configure s3-integrator:
```
juju deploy s3-integrator
juju config s3-integrator endpoint=http://MINIO_IP_ADDRESS:9000
juju config s3-integrator bucket=tempo
juju run s3-integrator/leader sync-s3-credentials access-key=YOUR_MINIO_ACCESS_KEY secret-key=YOUR_MINIO_SECRET
```

Deploy tempo:
```
juju deploy ./tempo-k8s_ubuntu-22.04-amd64.charm tempo --resource tempo-image=grafana/tempo:2.4.0
juju integrate tempo s3-integrator
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023 Ubuntu
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# Tempo Coordinator charm for Kubernetes
# Tempo Operator

[![CharmHub Badge](https://charmhub.io/tempo-coordinator-k8s/badge.svg)](https://charmhub.io/tempo-coordinator-k8s)
[![Release](https://github.com/canonical/tempo-coordinator-k8s-operator/actions/workflows/release.yaml/badge.svg)](https://github.com/canonical/tempo-coordinator-k8s-operator/actions/workflows/release.yaml)
[![CharmHub Badge](https://charmhub.io/tempo-k8s/badge.svg)](https://charmhub.io/tempo-k8s)
[![Release](https://github.com/canonical/tempo-k8s-operator/actions/workflows/release.yaml/badge.svg)](https://github.com/canonical/tempo-k8s-operator/actions/workflows/release.yaml)
[![Discourse Status](https://img.shields.io/discourse/status?server=https%3A%2F%2Fdiscourse.charmhub.io&style=flat&label=CharmHub%20Discourse)](https://discourse.charmhub.io)

## Description
This repository contains the source code for a Charmed Operator that drives [Tempo] on Kubernetes.

This charm serves as a coordinator for a Tempo HA deployment, together with the [tempo-worker-k8s](https://github.com/canonical/tempo-worker-k8s-operator) charm.
## Usage

Assuming you have access to a bootstrapped Juju controller on Kubernetes, you can:

```bash
$ juju deploy tempo-k8s # --trust (use when cluster has RBAC enabled)
```

## OCI Images

This charm, by default, deploys `grafana/tempo:2.4.0`.

## Contributing

See the [Juju SDK documentation](https://juju.is/docs/sdk) for more information about developing and improving charms.
Please see the [Juju SDK docs](https://juju.is/docs/sdk) for guidelines
on enhancements to this charm following best practice guidelines, and the
[contributing] doc for developer guidance.

[Tempo]: https://grafana.com/traces/
[contributing]: https://github.com/PietroPasotti/tempo-k8s-operator/blob/main/CONTRIBUTING.md
149 changes: 128 additions & 21 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,136 @@
# This file configures Charmcraft.
# See https://juju.is/docs/sdk/charmcraft-config for guidance.

# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
name: tempo-k8s
type: charm

assumes:
- k8s-api

# Juju 3.4.0 needed for pebble notify
- juju >= 3.4.0

description: |
Tempo is a distributed tracing backend by Grafana, supporting Jaeger,
Zipkin, and OpenTelemetry protocols.
summary: |
Tempo is a distributed tracing backend by Grafana.
links:
documentation: https://discourse.charmhub.io/t/tempo-k8s-docs-index/14005
website:
- https://charmhub.io/tempo-k8s
source:
- https://github.com/canonical/tempo-k8s-operator
issues:
- https://github.com/canonical/tempo-k8s-operator/issues

containers:
tempo:
resource: tempo-image
mounts:
- storage: data
location: /tmp/tempo

resources:
tempo-image:
type: oci-image
description: OCI image for Tempo
# Included for simplicity in integration tests
# see https://hub.docker.com/r/grafana/tempo/tags
upstream-source: grafana/tempo:2.4.0

provides:
tempo-cluster:
interface: tempo_cluster
description: |
Connect any number of tempo-worker-k8s charms to cluster the Tempo components off to different nodes.
grafana-dashboard:
interface: grafana_dashboard
description: |
Forwards the built-in grafana dashboard(s) for monitoring Tempo.
grafana-source:
interface: grafana_datasource
description: |
Configures Grafana to be able to use this Tempo instance as a datasource.
metrics-endpoint:
interface: prometheus_scrape
description: |
Exposes the Prometheus metrics endpoint providing telemetry about the
Tempo instance.
tracing:
interface: tracing
description: |
Integration to offer other charms the possibility to send traces to Tempo.
requires:
s3:
interface: s3
limit: 1
description: |
Obtains access to the s3 bucket for data storage.
logging:
interface: loki_push_api
description: |
Integration with Loki to push Tempo logs to the observability stack.
ingress:
interface: traefik_route
description: |
Ingress integration for Tempo server and Tempo receiver endpoints,
so that cross-model workloads can send their traces to Tempo through the ingress.
Uses `traefik_route` to open ports on Traefik host for tracing ingesters.
certificates:
interface: tls-certificates
limit: 1
description: |
Certificate and key files for securing Tempo internal and external
communications with TLS.
storage:
data:
type: filesystem
location: /tempo-data

actions:
list-receivers:
description: |
Returns a list of all enabled receiver endpoints.
peers:
tempo-peers:
interface: tempo_peers
description: |
peer relation for internal coordination
config:
options:
coordinator_runs_workload_when_clustered:
type: boolean
default: true
description: |
Whether this charm should also run a worker node when related
to any number of specialized worker applications.
Set it to ``false`` if you want this charm to stop running `Tempo`
as soon as you integrate it with a tempo-worker-k8s-charm instance.
In this case, tempo-k8s will only act as coordinator
(and reverse proxy) for the tempo cluster.
bases:
- build-on:
- name: ubuntu
channel: "22.04"
- name: "ubuntu"
channel: "22.04"
run-on:
- name: ubuntu
channel: "22.04"
- name: "ubuntu"
channel: "22.04"

parts:
charm:
charm-binary-python-packages:
- pydantic>2.0

# For v2.tls_certificates
- cryptography
- jsonschema

cos-tool:
plugin: dump
source: .
build-packages:
- curl
override-pull: |
curl -L -O https://github.com/canonical/cos-tool/releases/latest/download/cos-tool-${CRAFT_TARGET_ARCH}
chmod +x cos-tool-*
- "pydantic>=2"
- "cryptography"
- "jsonschema"
- "opentelemetry-exporter-otlp-proto-http==1.21.0"

1 change: 1 addition & 0 deletions icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 26 additions & 3 deletions lib/charms/data_platform_libs/v0/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _on_credential_gone(self, event: CredentialsGoneEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 4
LIBPATCH = 5

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -212,7 +212,7 @@ class S3CredentialEvents(CharmEvents):
class S3Provider(Object):
"""A provider handler for communicating S3 credentials to consumers."""

on = S3CredentialEvents() # pyright: ignore [reportGeneralTypeIssues]
on = S3CredentialEvents() # pyright: ignore [reportAssignmentType]

def __init__(
self,
Expand Down Expand Up @@ -481,6 +481,18 @@ def set_s3_api_version(self, relation_id: int, s3_api_version: str) -> None:
"""
self.update_connection_info(relation_id, {"s3-api-version": s3_api_version})

def set_delete_older_than_days(self, relation_id: int, days: int) -> None:
"""Sets the retention days for full backups in application databag.
This function writes in the application data bag, therefore,
only the leader unit can call it.
Args:
relation_id: the identifier for a particular relation.
days: the value.
"""
self.update_connection_info(relation_id, {"delete-older-than-days": str(days)})

def set_attributes(self, relation_id: int, attributes: List[str]) -> None:
"""Sets the connection attributes in application databag.
Expand Down Expand Up @@ -580,6 +592,17 @@ def s3_api_version(self) -> Optional[str]:

return self.relation.data[self.relation.app].get("s3-api-version")

@property
def delete_older_than_days(self) -> Optional[int]:
"""Returns the retention days for full backups."""
if not self.relation.app:
return None

days = self.relation.data[self.relation.app].get("delete-older-than-days")
if days is None:
return None
return int(days)

@property
def attributes(self) -> Optional[List[str]]:
"""Returns the attributes."""
Expand Down Expand Up @@ -613,7 +636,7 @@ class S3CredentialRequiresEvents(ObjectEvents):
class S3Requirer(Object):
"""Requires-side of the s3 relation."""

on = S3CredentialRequiresEvents() # pyright: ignore[reportGeneralTypeIssues]
on = S3CredentialRequiresEvents() # pyright: ignore[reportAssignmentType]

def __init__(
self, charm: ops.charm.CharmBase, relation_name: str, bucket_name: Optional[str] = None
Expand Down
Loading

0 comments on commit 5931889

Please sign in to comment.