Skip to content
Open
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
80 changes: 57 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,61 @@
# Copyright 2019 Google LLC

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.9-slim
RUN apt-get update && \
apt-get install -y \
build-essential \
make \
gcc \
locales

ARG PYTHON_VERSION=3.12.7

FROM python:${PYTHON_VERSION}-alpine as builder

ADD . /app
WORKDIR /app

#COPY . ./

RUN apk add psmisc
RUN apk add bash
RUN apk add curl
RUN apk add vim
RUN apk add gcc
RUN apk add musl-dev
RUN apk add libc-dev
RUN apk add make

RUN cd /app/slo_generator/exporters/gen && make generate

RUN pip install --upgrade pip
RUN pip install -U setuptools
RUN pip install ."[api, datadog, dynatrace, prometheus, elasticsearch, pubsub, cloud_monitoring, cloud_service_monitoring, cloud_storage, bigquery, cloudevent, dev]"

RUN pip install --no-cache-dir ."[ \
api, \
prometheus, \
prometheus_remote_write \
]"

# RUN pip install --no-cache-dir ."[ \
# api, \
# bigquery, \
# cloud_monitoring, \
# cloud_service_monitoring, \
# cloud_storage, \
# cloudevent, \
# datadog, \
# dynatrace, \
# elasticsearch, \
# opensearch, \
# prometheus, \
# pubsub, \
# splunk, \
# prometheus_remote_write \
# ]"


FROM python:${PYTHON_VERSION}-alpine

RUN apk add bash
RUN apk add curl
RUN apk add vim

WORKDIR /

COPY --from=builder /usr/local /usr/local

ENTRYPOINT [ "slo-generator" ]
CMD ["-v"]

CMD [ "-v" ]
140 changes: 70 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# useful targets:
# make clean -- clean distutils
# make coverage -- code coverage report
# make test -- run lint + unit tests
# make lint -- run lint tests separately
# make unit -- runs unit tests separately
# make integration -- runs integration tests
# make test -- run linting + unit tests + audit CVEs
# make lint -- run linting separately
# make unit -- run unit tests separately
# make audit -- run CVE scan separately
# make integration -- run integration tests
########################################################
# variable section

Expand Down Expand Up @@ -58,12 +59,12 @@ develop: install
pre-commit install

install: clean
$(PIP) install -e ."[api, datadog, prometheus, elasticsearch, pubsub, cloud_monitoring, bigquery, dev]"
$(PIP) install -e ."[api, datadog, prometheus, elasticsearch, opensearch, splunk, pubsub, cloud_monitoring, bigquery, dev]"

uninstall: clean
$(PIP) freeze --exclude-editable | xargs $(PIP) uninstall -y

test: install unit lint
test: install unit lint audit

unit: clean
pytest --cov=$(NAME) tests -p no:warnings
Expand All @@ -72,37 +73,32 @@ coverage:
$(COVERAGE) report --rcfile=".coveragerc"

format:
isort .
black .
ruff format

lint: black isort flake8 pylint pytype mypy bandit safety
lint: ruff pytype mypy

black:
black . --check

isort:
isort . --check-only

flake8:
flake8 $(NAME)/
flake8 tests/

pylint:
find ./$(NAME) ./tests -type f -name "*.py" | xargs pylint
ruff:
ruff format --check
ruff check

pytype:
pytype

mypy:
mypy --show-error-codes $(NAME)

audit: bandit safety

bandit:
bandit .
bandit -r $(NAME)

safety:
safety check
# Ignore:
# - CVE-2018-20225 with Vulnerability ID 67599, as we do not use the `--extra-index-url` option, and the behavior is intended anyway.
# - CVE-2019-8341 with vulnerability ID 70612, as we do not use untrusted templates without sandboxing.
safety check --ignore 67599 --ignore 70612

integration: int_cm int_csm int_custom int_dd int_dt int_es int_prom
integration: int_cm int_csm int_custom int_dd int_dt int_es int_prom int_sp int_os

int_cm:
slo-generator compute -f samples/cloud_monitoring -c samples/config.yaml
Expand All @@ -125,57 +121,61 @@ int_es:
int_prom:
slo-generator compute -f samples/prometheus -c samples/config.yaml

int_sp:
slo-generator compute -f samples/splunk -c samples/config.yaml

int_os:
slo-generator compute -f samples/opensearch -c samples/config.yaml

# Run API locally
run_api:
slo-generator api --target=run_compute --signature-type=http -c samples/config.yaml

# Local Docker build / push
# Build Docker image locally
docker_build:
DOCKER_BUILDKIT=1
docker build -t slo-generator:latest .

docker_test: docker_build
docker run --entrypoint "make" \
-e GOOGLE_APPLICATION_CREDENTIALS=tests/unit/fixtures/fake_credentials.json \
slo-generator test

# Cloudbuild
cloudbuild: gcloud_alpha
gcloud alpha builds submit \
--config=cloudbuild.yaml \
--project=${CLOUDBUILD_PROJECT_ID} \
--substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION}

# Cloudrun
cloudrun:
#docker buildx create --name multi-arch --platform "linux/arm64,linux/amd64,linux/arm/v7" --driver "docker-container"
docker buildx use multi-arch
docker buildx build . --platform linux/amd64,linux/arm64 -t slo-generator:latest

# Build Docker image locally
docker_build_local:
docker build --no-cache . -t slo-generator:latest

# Build Docker image with Cloud Build
cloud_build:
gcloud builds submit \
--config=cloudbuild.yaml \
--project=${CLOUDBUILD_PROJECT_ID} \
--substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION},_PYTHON_VERSION=${PYTHON_VERSION}

# Cloud Run
cloud_run:
gcloud run deploy slo-generator \
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="${SIGNATURE_TYPE}" \
--min-instances 1 \
--allow-unauthenticated

# Cloudrun - export mode only
cloudrun_export_only:
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="${SIGNATURE_TYPE}" \
--min-instances 1 \
--allow-unauthenticated

# Cloud Run - Export Mode Only
cloud_run_export_only:
gcloud run deploy slo-generator-export \
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="cloudevent" \
--args=--target="run_export" \
--min-instances 1 \
--allow-unauthenticated

gcloud_alpha:
gcloud components install alpha --quiet
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="cloudevent" \
--args=--target="run_export" \
--min-instances 1 \
--allow-unauthenticated
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
[![PyPI version](https://badge.fury.io/py/slo-generator.svg)](https://badge.fury.io/py/slo-generator)
[![Downloads](https://static.pepy.tech/personalized-badge/slo-generator?period=total&units=international_system&left_color=grey&right_color=orange&left_text=pypi%20downloads)](https://pepy.tech/project/slo-generator)

This a a fork from the `Google ([slo-generator](https://github.com/google/slo-generator))`
This forks adds:

* support to prometheus_remote_write tks to ([slo-generator oktocat](https://github.com/oktocat/slo-generator/tree/prometheus-remotewrite-exporter))
* support to build in arm architecture
* upgrade python to 3.12.7
* SLO-Generator is instrumented, tks to ([Carlos Martins](https://github.com/casmssm)) for the help


`slo-generator` is a tool to compute and export **Service Level Objectives** ([SLOs](https://landing.google.com/sre/sre-book/chapters/service-level-objectives/)), **Error Budgets** and **Burn Rates**, using configurations written in YAML (or JSON) format.

***IMPORTANT NOTE: the following content is the `slo-generator` v2 documentation. The v1 documentation is available [here](https://github.com/google/slo-generator/tree/v1.5.1), and instructions to migrate to v2 are available [here](https://github.com/google/slo-generator/blob/master/docs/shared/migration.md).***
Expand Down
67 changes: 67 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
backends:
prometheus:
url: "http://192.168.25.200:9090"

exporters:
prometheus_remote_write:
url: "http://192.168.25.200:9090/api/v1/write"
metrics:
- "error_budget_burn_rate"
- "error_budget_target"
- "alerting_burn_rate_threshold"
- "events_count"
- "sli_measurement"
- "slo_target"
- "alert"
- "error_minutes"
- "error_budget_minutes"
- "bad_events_count"
- "error_budget_remaining_minutes"
- "gap"
- "good_events_count"

error_budget_policies:
default:
steps:
- name: 5 min
burn_rate_threshold: 14.4
alert: true
message_alert: Page to defend the SLO
message_ok: Last hour on track
window: 300
- name: 1 hour
burn_rate_threshold: 14.4
alert: true
message_alert: Page to defend the SLO
message_ok: Last hour on track
window: 3600
- name: 30 min
burn_rate_threshold: 6
alert: true
message_alert: Page to defend the SLO
message_ok: Last 12 hours on track
window: 1800
- name: 6 hours short
burn_rate_threshold: 6
alert: false
message_alert: Dev team dedicates 25% of engineers to the reliability backlog
message_ok: Last week on track
window: 21600
- name: 6 hours long
burn_rate_threshold: 1
alert: false
message_alert: Dev team dedicates 25% of engineers to the reliability backlog
message_ok: Last week on track
window: 21600
- name: 3 days
burn_rate_threshold: 1
alert: false
message_alert: Dev team dedicates 25% of engineers to the reliability backlog
message_ok: Last week on track
window: 259200
- name: 28 days
burn_rate_threshold: 1
alert: false
message_alert: Freeze release, unless related to reliability or security
message_ok: Unfreeze release, per the agreed roll-out policy
window: 2419200
Loading