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

blackbox exporter charm #1

Merged
merged 26 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Bug Report
description: File a bug report
labels: ["Type: Bug", "Status: Triage"]
body:
- type: markdown
attributes:
value: >
Thanks for taking the time to fill out this bug report! Before submitting your issue, please make
sure you are using the latest version of the charm. If not, please switch to this image prior to
posting your report to make sure it's not already solved.
- type: textarea
id: bug-description
attributes:
label: Bug Description
description: >
If applicable, add screenshots to help explain your problem. If applicable, add screenshots to
help explain the problem you are facing.
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: To Reproduce
description: >
Please provide a step-by-step instruction of how to reproduce the behavior.
placeholder: |
1. `juju deploy ...`
2. `juju relate ...`
3. `juju status --relations`
validations:
required: true
- type: textarea
id: environment
attributes:
label: Environment
description: >
We need to know a bit more about the context in which you run the charm.
- Are you running Juju locally, on lxd, in multipass or on some other platform?
- What track and channel you deployed the charm from (ie. `latest/edge` or similar).
- Version of any applicable components, like the juju snap, the model controller, lxd, microk8s, and/or multipass.
validations:
required: true
- type: textarea
id: logs
attributes:
label: Relevant log output
description: >
Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
Fetch the logs using `juju debug-log --replay` and `kubectl logs ...`. Additional details available in the juju docs
at https://juju.is/docs/olm/juju-logs
render: shell
validations:
required: true
- type: textarea
id: additional-context
attributes:
label: Additional context

17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement_proposal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Enhancement Proposal
description: File an enhancement proposal
labels: ["Type: Enhancement", "Status: Triage"]
body:
- type: markdown
attributes:
value: >
Thanks for taking the time to fill out this enhancement proposal! Before submitting your issue, please make
sure there isn't already a prior issue concerning this. If there is, please join that discussion instead.
- type: textarea
id: enhancement-proposal
attributes:
label: Enhancement Proposal
description: >
Describe the enhancement you would like to see in as much detail as needed.
validations:
required: true
11 changes: 11 additions & 0 deletions .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Issues

on: [issues]

jobs:
update:
name: Update Issue
uses: canonical/observability/.github/workflows/issues.yaml@main
secrets: inherit
with:
component: blackbox-exporter
20 changes: 20 additions & 0 deletions .github/workflows/promote.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Promote Charm

on:
workflow_dispatch:
inputs:
promotion:
type: choice
description: Channel to promote from
options:
- edge -> beta
- beta -> candidate
- candidate -> stable

jobs:
promote:
name: Promote
uses: canonical/observability/.github/workflows/charm-promote.yaml@main
with:
promotion: ${{ github.event.inputs.promotion }}
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Pull Requests

on:
pull_request:
branches:
- main

jobs:
pull-request:
name: PR
uses: canonical/observability/.github/workflows/charm-pull-request.yaml@main
secrets: inherit
11 changes: 11 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Release Charm to Edge and Publish Libraries

on:
push:
branches:
- main

jobs:
release:
uses: canonical/observability/.github/workflows/charm-release.yaml@main
secrets: inherit
14 changes: 14 additions & 0 deletions .github/workflows/update-libs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Auto-update Charm Libraries
on:
# Manual trigger
workflow_dispatch:
# Check regularly the upstream every four hours
schedule:
- cron: "0 0,4,8,12,16,20 * * *"

jobs:
update-lib:
name: Check libraries
uses: canonical/observability/.github/workflows/charm-update-libs.yaml@main
secrets: inherit

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*~
*swp
*.charm
.coverage
.tox
__pycache__
build
venv
.idea
.vscode
.hypothesis/*
9 changes: 9 additions & 0 deletions .jujuignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/venv
*.py[cod]
*.charm
.flake8
tests
tox.ini
CONTRIBUTING.md
INTEGRATING.md
RELEASE.md
1 change: 1 addition & 0 deletions .wokeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**
lucabello marked this conversation as resolved.
Show resolved Hide resolved
96 changes: 96 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Contributing to blackbox-exporter-k8s
![GitHub](https://img.shields.io/github/license/canonical/blackbox-exporter-k8s-operator)
![GitHub commit activity](https://img.shields.io/github/commit-activity/y/canonical/blackbox-exporter-k8s-operator)
![GitHub](https://img.shields.io/tokei/lines/github/canonical/blackbox-exporter-k8s-operator)
![GitHub](https://img.shields.io/github/issues/canonical/blackbox-exporter-k8s-operator)
![GitHub](https://img.shields.io/github/issues-pr/canonical/blackbox-exporter-k8s-operator) ![GitHub](https://img.shields.io/github/contributors/canonical/blackbox-exporter-k8s-operator) ![GitHub](https://img.shields.io/github/watchers/canonical/blackbox-exporter-k8s-operator?style=social)

## Overview

This documents explains the processes and practices recommended for
contributing enhancements or bug fixing to the Blackbox Exporter Charmed Operator.

The intended use case of this operator is to be deployed as part of the
[COS Lite] bundle, although that is not necessary.


## Setup

A typical setup using [snaps](https://snapcraft.io/) can be found in the
[Juju docs](https://juju.is/docs/sdk/dev-setup).


## Developing

- Prior to getting started on a pull request, we first encourage you to open an
issue explaining the use case or bug.
This gives other contributors a chance to weigh in early in the process.
- To author PRs you should be familiar with [juju](https://juju.is/#what-is-juju)
and [how operators are written](https://juju.is/docs/sdk).
- The best way to get a head start is to join the conversation on our
[Mattermost channel] or [Discourse].
- All enhancements require review before being merged. Besides the
code quality and test coverage, the review will also take into
account the resulting user experience for Juju administrators using
this charm. To be able to merge you would have to rebase
onto the `main` branch. We do this to avoid merge commits and to have a
linear Git history.
- We use [`tox`](https://tox.wiki/en/latest/#) to manage all virtualenvs for
the development lifecycle.


### Testing
Unit tests are written with the Operator Framework [test harness] and
integration tests are written using [pytest-operator] and [python-libjuju].

The default test environments - lint, static and unit - will run if you start
`tox` without arguments.

You can also manually run a specific test environment:

```shell
tox -e fmt # update your code according to linting rules
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e scenario # scenario tests
tox -e integration # integration tests
```

`tox` creates a virtual environment for every tox environment defined in
[tox.ini](tox.ini). To activate a tox environment for manual testing,

```shell
source .tox/unit/bin/activate
```


## Build charm

Build the charm in this git repository using

```shell
charmcraft pack
```

which will create a `*.charm` file you can deploy with:

```shell
juju deploy ./blackbox-exporter-k8s.charm \
--resource blackbox-exporter-image=ubuntu/blackbox-exporter \
--config config_file='@path/to/blackbox-exporter.yaml'
```


## Design choices
- The `config.yaml` config file is created in its entirety by the charm
code on startup. This is done to maintain consistency across OCI images.

[gh:Prometheus operator]: https://github.com/canonical/prometheus-k8s-operator
[Prometheus operator]: https://charmhub.io/prometheus-k8s
[COS Lite]: https://charmhub.io/cos-lite
[Mattermost channel]: https://chat.charmhub.io/charmhub/channels/observability
[Discourse]: https://discourse.charmhub.io/tag/blackbox-exporter
[test harness]: https://ops.readthedocs.io/en/latest/#module-ops.testing
[pytest-operator]: https://github.com/charmed-kubernetes/pytest-operator/blob/main/docs/reference.md
[python-libjuju]: https://pythonlibjuju.readthedocs.io/en/latest/
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Discourse Status](https://img.shields.io/discourse/status?server=https%3A%2F%2Fdiscourse.charmhub.io&style=flat&label=CharmHub%20Discourse)](https://discourse.charmhub.io)

[Charmed Blackbox Exporter (blackbox-exporter-k8s)][Blackbox Exporter operator] is a charm for
[Alertmanager].
[Blackbox Exporter].

The charm imposes configurable resource limits on the workload, can be readily
integrated with [prometheus][Prometheus operator], [grafana][Grafana operator]
Expand Down Expand Up @@ -53,25 +53,41 @@ juju status --relations --storage --color
### Configuration

In order to configure the Blackbox Exporter, a [configuration file](https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md)
must be provided using the
should be provided using the
[`config_file`](https://charmhub.io/blackbox-exporter-k8s/conigure#config_file) option:

```shell
juju config blackbox-exporter-k8s \
config_file='@path/to/blackbox-exporter.yaml'
config_file='@path/to/blackbox.yml'
```


To verify Blackbox Exporter is using the expected configuration you can use the
[`show-config`](https://charmhub.io/blackbox-exporter-k8s/actions#show-config) action:

```shell
juju run-action blackbox-exporter-k8s/0 show-config --wait
```

To configure the actual probes, there first needs to be a Prometheus relation:

```shell
juju relate blackbox-exporter-k8s prometheus
```

Then, the probes configuration should be written to a file (following the
[Blackbox Exporter docs](https://github.com/prometheus/blackbox_exporter#prometheus-configuration)
) and passed via `juju config`:

```shell
juju config blackbox-exporter-k8s \
probes_file='@path/to/probes.yml'
```

Note that the `relabel_configs` of each scrape job doesn't need to be specified, and will be
overridden by the charm with the needed labels and the correct Blackbox Exporter url.

## OCI Images
This charm is published on Charmhub with alertmanager images from
This charm is published on Charmhub with blackbox exporter images from
the official [quay.io/prometheus/blackbox-exporter].

[quay.io/prometheus/blackbox-exporter]: https://quay.io/repository/prometheus/blackbox-exporter?tab=tags
Expand Down
5 changes: 5 additions & 0 deletions actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.

show-config:
description: Show Blackbox Exporter config file.
14 changes: 14 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"
parts:
charm:
charm-binary-python-packages: [ops, PyYAML, cryptography, jsonschema]
32 changes: 32 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.

options:
config_file:
type: string
default: ""
lucabello marked this conversation as resolved.
Show resolved Hide resolved
description: >
Blackbox Exporter configuration file (yaml).
Refer to https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md for
full details.
lucabello marked this conversation as resolved.
Show resolved Hide resolved
probes_file:
type: string
default: ""
description: >
Scrape config for Prometheus in a file (yaml).
Refer to https://github.com/prometheus/blackbox_exporter#prometheus-configuration for full
details.
cpu:
description: |
K8s cpu resource limit, e.g. "1" or "500m". Default is unset (no limit). This value is used
for the "limits" portion of the resource requirements (the "requests" portion is
automatically deduced from it).
See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: string
memory:
description: |
K8s memory resource limit, e.g. "1Gi". Default is unset (no limit). This value is used
for the "limits" portion of the resource requirements (the "requests" portion is
automatically deduced from it).
See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: string
Loading
Loading