Skip to content

Commit

Permalink
Merge pull request #21 from portefaix/feat/mixins-import
Browse files Browse the repository at this point in the history
Mixins import
  • Loading branch information
nlamirault committed Mar 5, 2021
2 parents 63059af + f130e52 commit 6cab53d
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 84 deletions.
11 changes: 8 additions & 3 deletions Makefile
Expand Up @@ -28,10 +28,15 @@ clean: ## Cleanup
.PHONY: check
check: check-poetry check-helm ## Check requirements

.PHONY: init ## Initialize environment
init:
.PHONY: init
init: ## Initialize environment
poetry install
$(ANSIBLE_VENV)/bin/pre-commit install
$(VENV)/bin/pre-commit install

# .PHONY: init ## Initialize environment
# init:
# poetry install
# $(ANSIBLE_VENV)/bin/pre-commit install

# ====================================
# H E L M
Expand Down
2 changes: 1 addition & 1 deletion charts/thanos-mixin/Chart.yaml
Expand Up @@ -28,7 +28,7 @@ keywords:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.7.0
version: 0.8.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
2 changes: 1 addition & 1 deletion charts/thanos-mixin/README.md
@@ -1,6 +1,6 @@
# thanos-mixin

![Version: 0.7.0](https://img.shields.io/badge/Version-0.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.17.1](https://img.shields.io/badge/AppVersion-0.17.1-informational?style=flat-square)
![Version: 0.8.0](https://img.shields.io/badge/Version-0.8.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.17.1](https://img.shields.io/badge/AppVersion-0.17.1-informational?style=flat-square)

A Helm chart for Thanos Mixin

Expand Down
151 changes: 101 additions & 50 deletions charts/thanos-mixin/templates/alerts.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion charts/thanos-mixin/templates/rules.yaml
Expand Up @@ -135,4 +135,4 @@ spec:
quantile: "0.99"
record: :thanos_objstore_bucket_operation_duration_seconds:histogram_quantile
- name: thanos-bucket-replicate.rules
rules: []
rules: []
2 changes: 1 addition & 1 deletion hack/commons.mk
Expand Up @@ -25,7 +25,7 @@ SHELL = /bin/bash -o pipefail
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))

ANSIBLE_VENV = $(MKFILE_DIR)/../.venv
VENV = $(MKFILE_DIR)/../.venv

NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
Expand Down
83 changes: 83 additions & 0 deletions hack/mixins.py
@@ -0,0 +1,83 @@
#!/usr/bin/env python3

# Copyright (C) 2020-2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>

# 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.

import glob
import logging
import os
from os import path
import shutil
import zipfile

import coloredlogs
import requests


MIXINS_VERSION="v0.1.0"
MIXIN_ARCHIVE="portefaix-mixins-%s.zip" % MIXINS_VERSION
MIXIN_URL="https://github.com/nlamirault/monitoring-mixins/releases/download/%s/%s" % (
MIXINS_VERSION, MIXIN_ARCHIVE
)
MIXIN_DIRECTORY="portefaix-mixins"

DIR="portefaix-mixins"

logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG')


def escape(s):
return s.replace("{{", "{{`{{").replace("}}", "}}`}}").replace("{{`{{", "{{`{{`}}").replace("}}`}}", "{{`}}`}}")


def download(url, filename):
logger.info("Download Mixin : %s", url)
r = requests.get(url)
with open(filename,'wb') as f:
f.write(r.content)


def manage_mixin(mixin_directory, mixin):
logger.info("Manage %s", mixin)
chart_dst = "charts/%s/templates/" % mixin
files = glob.glob("%s/%s/manifests/*.yaml" % (mixin_directory, mixin))
for f in files:
orig = "%s" % f
dest = "%s/%s" % (chart_dst, path.basename(orig))
if os.path.exists(chart_dst):
if os.path.exists(dest):
os.remove(dest)
logger.debug("Copy %s", f)
fin = open(orig, "rt")
fout = open(dest, "wt")
for line in fin:
fout.write(escape(line))
else:
logger.warning("Mixin chart not found")


def main(url, filename, mixin_directory):
download(url, filename)
with zipfile.ZipFile(filename,"r") as zf:
zf.extractall()
logger.info("Monitoring mixins")
for mixin in os.listdir(path=mixin_directory):
manage_mixin(mixin_directory, mixin)
os.remove(filename)
shutil.rmtree(mixin_directory)


if __name__ == '__main__':
main(MIXIN_URL, MIXIN_ARCHIVE, MIXIN_DIRECTORY)

0 comments on commit 6cab53d

Please sign in to comment.