Skip to content

Commit

Permalink
Merge pull request #20 from chelnak/exporter_refresh
Browse files Browse the repository at this point in the history
Exporter refresh
  • Loading branch information
chelnak authored Dec 2, 2022
2 parents 259e05f + 75a96bf commit 047789e
Show file tree
Hide file tree
Showing 25 changed files with 1,320 additions and 452 deletions.
85 changes: 44 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: status-cake-exporter
name: "ci"

on:
push:
Expand All @@ -7,51 +7,59 @@ on:
pull_request:
branches:
- main
workflow_dispatch:

env:
IMAGE_NAME: status-cake-exporter

jobs:
build:
runs-on: ubuntu-latest
ci:
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v2

- uses: "actions/checkout@v3"
with:
fetch-depth: 0
- name: Set up Python 🐍
uses: actions/setup-python@v2
fetch-depth: 0

- name: "set up python"
uses: "actions/setup-python@v2"
with:
python-version: 3.8
python-version: '3.10'

- name: Install Dependencies 🚧
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: "install poetry"
uses: "snok/install-poetry@v1"
with:
virtualenvs-in-project: true

- name: Lint 🍻
run: |
python -m flake8 exporter/ --max-line-length=120 --tee
- name: "install dependencies"
run: poetry install

# - name: Test ✅
# run: |
# python setup.py test
- name: "build"
run: |
source $VENV
make build
- name: Build image 🐳
run: docker build . --file Dockerfile --tag status-cake-exporter
- name: "get version"
id: "get_version"
run: |
current_version=$(poetry version -s)
echo "version=$current_version" >> $GITHUB_OUTPUT
- name: Log into registry 🐳
- name: "build image"
run: |
docker build . --file Dockerfile --tag status-cake-exporter
- name: "log into registry"
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image 🐳
- name: "push image"
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
if [[ "${{ github.ref }}" == "refs/tags/v"* ]]; then
docker tag $IMAGE_NAME $IMAGE_ID:$(echo $VERSION | sed -e 's/^v//')
# latest should always reflect the most recent tagged release
VERSION=latest
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
Expand All @@ -61,26 +69,21 @@ jobs:
# dev represents the latest build from prs or branches
VERSION=dev
fi
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push -a $IMAGE_ID
env:
GITVERSION_MAJORMINORPATCH: ${{ steps.gitversion.outputs.majorMinorPatch }}
- name: Build Changelog 📝
- name: "create release"
if: startsWith(github.ref, 'refs/tags/v')
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v1
with:
configuration: "changelog.json"
run: |
gh release create v${{ steps.get_version.outputs.version }} ./dist/*.whl --title v${{ steps.get_version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release 🚀
- name: "publish"
if: startsWith(github.ref, 'refs/tags/v')
id: create_release
uses: ncipollo/release-action@v1
with:
name: status-cake-exporter
body: ${{steps.build_changelog.outputs.changelog}}
token: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry config pypi-token.pypi $POETRY_PYPI_TOKEN_PYPI
poetry publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}

80 changes: 80 additions & 0 deletions .github/workflows/release_prep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "Release Prep"

on:
workflow_dispatch:
inputs:
version:
description: "The version number for the next release."
required: true
type: choice
options:
- patch
- minor
- major
target:
description: "The target for the release. This can be a commit sha or a branch."
required: false
default: "main"
type: "string"

jobs:
release_prep:
name: "release prep"
runs-on: "ubuntu-latest"

steps:

- name: "checkout"
uses: "actions/checkout@v3"
with:
ref: ${{ github.event.inputs.target }}
clean: true
fetch-depth: 0

- name: "set up python"
uses: "actions/setup-python@v2"
with:
python-version: '3.10'

- name: "install poetry"
uses: "snok/install-poetry@v1"
with:
virtualenvs-in-project: true

- name: "install dependencies"
run: |
poetry install
- name: "bump version"
id: "bump_version"
run: |
next_version=$(poetry version ${{ github.event.inputs.version }} -s)
echo "version=$next_version" >> $GITHUB_OUTPUT
- name: "generate changelog"
run: |
export GH_HOST=github.com
gh extension install chelnak/gh-changelog
gh changelog new --next-version v${{ steps.bump_version.outputs.version }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "commit changes"
run: |
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
git config --local user.name "GitHub Actions"
git add .
git commit -m "Release prep v${{ steps.bump_version.outputs.version }}"
- name: "create pull request"
uses: "peter-evans/create-pull-request@v4"
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Release prep v${{ steps.bump_version.outputs.version }}"
branch: "release-prep"
delete-branch: true
title: "Release prep v${{ steps.bump_version.outputs.version }}"
base: "main"
body: |
Automated release-prep from commit ${{ github.sha }}.
labels: "maintenance"
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/terrencepreilly/darglint
rev: master
hooks:
- id: darglint
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
FROM python:3.7.4-alpine3.10
FROM python:3.10-alpine

ADD exporter exporter/
ADD requirements.txt exporter/requirements.txt

WORKDIR exporter

RUN pip install -r requirements.txt
COPY dist/ /tmp/
RUN pip install --no-cache-dir /tmp/status_cake_exporter*.whl

EXPOSE 8000

CMD ["python", "app.py"]
ENTRYPOINT ["status-cake-exporter"]
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.DEFAULT_GOAL:= build
SHELL := /bin/bash
VENV ?= "$(shell poetry env list --full-path | cut -f1 -d " ")/bin/activate"

# Releasing
tag:
@git tag -a $(version) -m "Release $(version)"
@git push --follow-tags

# Building
build: check
@source $(VENV)
@rm -rf dist || true
@poetry build

check:
@source $(VENV)
@poetry run black --check .
@poetry run isort --check .
@poetry run flake8 status_cake_exporter --max-line-length=120 --tee
@poetry run darglint -s google -m "{path}:{line} -> {msg_id}: {msg}" status_cake_exporteri


# Developing
.PHONY: init
init:
@poetry install
@pre-commit install

.PHONY: fix
fix:
@source $(VENV)
@poetry run black .
@poetry run isort .
55 changes: 19 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ http://status-cake-exporter.default.svc:8000

## Requirements

* Python 3.7 (not tested with anything below this)
* Python dependencies from `requirements.txt`
* Python 3.10+
* Docker
* Kubernetes (optional)
* Helm 3 (optional)
Expand All @@ -24,9 +23,6 @@ http://status-cake-exporter.default.svc:8000

| Setting | Required | Default |
|--------------------------------------|----------|---------|
| USE_V1_UPTIME_ENDPOINTS | No | False |
| USE_V1_MAINTENANCE_WINDOWS_ENDPOINTS | No | False |
| USERNAME | Yes | Null |
| API_KEY | Yes | Null |
| TAGS | No | Null |
| LOG_LEVEL | No | info |
Expand All @@ -37,14 +33,13 @@ http://status-cake-exporter.default.svc:8000
The following will expose the exporter at `localhost:8000`:

```sh
export USERNAME=statuscakeuser
export API_KEY=xxxxxxxx
docker run -d -p 8000:8000 --env USERNAME --env API_KEY ghcr.io/chelnak/status-cake-exporter:latest
docker run -d -p 8000:8000 --env API_KEY ghcr.io/chelnak/status-cake-exporter:latest
```

### Kubernetes

To get up and running quickly, use [examples/manifest.yml](examples/manifest.yml) as an example. You will need to create a secret named `status-cake-api-token` containing your `USERNAME` and `API_KEY` first.
To get up and running quickly, use [examples/manifest.yml](examples/manifest.yml) as an example. You will need to create a secret named `status-cake-api-token` containing your `API_KEY` first.

Otherwise, you can use the Helm Chart provided in [chart/status-cake-exporter](chart/status-cake-exporter/README.md).

Expand All @@ -55,35 +50,23 @@ To get up and running quickly, use [examples/grafana-example.json](examples/graf
### Terminal

```sh
usage: app.py [-h] [--username USERNAME] [--api-key API_KEY]
[--tests.tags TAGS] [--logging.level {debug,info,warn,error}] [--port PORT]

If an arg is specified in more than one place, then commandline values
override environment variables which override defaults.

optional arguments:
-h, --help show this help message and exit
--use_v1_uptime_endpoints true Boolean for using v1 uptime endpoints [env var: USE_V1_UPTIME_ENDPOINTS]
--use_v1_maintenance_windows_endpoints true Boolean for using v1 maintenance windows endpoints [env var: USE_V1_MAINTENANCE_WINDOWS_ENDPOINTS]
--username USERNAME Username for the account [env var: USERNAME]
--api-key API_KEY API key for the account [env var: API_KEY]
--tests.tags TAGS A comma separated list of tags used to filter tests returned from the api [env var: TAGS]
--logging.level {debug,info,warn,error} Set a log level for the application [env var: LOG_LEVEL]
--port The TCP port to start the web server on [env var: PORT]
Usage: status-cake-exporter [OPTIONS]

Options:
--api-key TEXT API Key for the account. [env var: API_KEY;
required]
--tags TEXT A comma separated list of tags used to filter tests
returned from the api [env var: TAGS]
--log-level TEXT The log level of the application. Value can be one of
{debug, info, warn, error} [env var: LOG_LEVEL;
default: info]
--port INTEGER [env var: PORT; default: 8000]
--items-per-page TEXT The number of items that the api will return on a
page. This is a global option. [env var:
ITEMS_PER_PAGE; default: 25]
--help Show this message and exit
```

## V1 API
StatusCake have a new v1 API with documentation available at https://www.statuscake.com/api/v1/, deprecating the legacy API https://www.statuscake.com/api/.

The new `Get all uptime tests` endpoint https://www.statuscake.com/api/v1/#operation/list-uptime-tests provides paged responses to get all tests, overcoming the limit of only 100 tests in the response from the legacy API https://www.statuscake.com/api/Tests/Get%20All%20Tests.md

Environment variables `USE_V1_UPTIME_ENDPOINTS` and `USE_V1_MAINTENANCE_WINDOWS_ENDPOINTS` are used to enable use of the v1 API.

### Maintenance Windows endpoints
Endpoints of the new v1 API are available to be used by all accounts with the exception of the maintenance windows endpoints, from https://www.statuscake.com/api/v1/#tag/uptime:
>NOTE: the API endpoints concerned with maintenance windows will only work with accounts registed to use the newer version of maintenance windows. This version of maintenance windows is incompatible with the original version and all existing windows will require migrating to be further used. Presently a tool to automate the migration of maintenance windows is under development.
Similarly, if an account is registered to use the newer version of maintenance windows, the legacy API's maintenance windows endpoints cannot be used.

## Metrics

| Name| Type | Description |
Expand All @@ -93,7 +76,7 @@ Similarly, if an account is registered to use the newer version of maintenance w

## Prometheus

Prometheus config needs to be updated in order to see the new exported. Use the following scrape config as an example:
Prometheus config needs to be updated to see the new exported. Use the following scrape config as an example:

```Yaml
scrape_configs:
Expand Down
Loading

0 comments on commit 047789e

Please sign in to comment.