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

Add Alloy mixin update script and Makefile #607

Merged
merged 6 commits into from
Aug 22, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
output/
tools/*
!tools/.gitkeep
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added Makefile.custom.mk to group scripts usage
- Added `make update-mixin` to update mixin dasbhboards
- Added `make lint-dashboards` to dashboards linting
- Added `make install-tools` to install required tools

- Added `scripts/update-alloy-mixin.sh` to update the Alloy mixin dashboards

### Changed

- Updated all dashboars using `decbytes` unit to use `bytes` (IEC units) instead.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# https://github.com/giantswarm/devctl/blob/6a704f7e2a8b0f09e82b5bab88f17971af849711/pkg/gen/input/makefile/internal/file/Makefile.template
#

include Makefile.*.mk

##@ General

# The help target prints out all targets with their descriptions organized
Expand All @@ -23,3 +21,5 @@ include Makefile.*.mk
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z%\\\/_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

include Makefile.*.mk
TheoBrigitte marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions Makefile.custom.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##@ Dashboards

.PHONY: install-tools update-mimir-mixin update-alloy-mixin lint-dashboards

SHELL:=/bin/bash -O globstar

dashboards = helm/dashboards/dashboards/**/*.json helm/dashboards/charts/**/*.json

install-tools: ## Install dependencies tools
./scripts/install-tools.sh

update-mimir-mixin: install-tools ## Update Mimir mixin dashboards
./mimir/update.sh

update-alloy-mixin: install-tools ## Update Alloy mixin dashboards
./scripts/update-alloy-mixin.sh

update-mixin: update-mimir-mixin update-alloy-mixin ## Update all mixins dashboards

lint-dashboards: install-tools ## Run dashboard-linter for all dashboards in the helm/dashboards directory
@for file in $(dashboards); do \
echo "------ Linting $$file"; \
dashboard-linter lint -c linter/config.yaml $$file; \
done
@echo "------ Linted $(shell echo $(dashboards) | wc -w) dashboards"
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ Atlas introduced a dashboard linter to ensure some basic dashboard rules are fol
This will most likely be moved to CI later but until it is you can run it like this:

```sh
# Install the tool
go install github.com/grafana/dashboard-linter@latest
### Run on a specific dashboard
dashboard-linter lint -c linter/config.yaml <dashboard_location>
make lint-dashboards
```

If you need help with the tool or its output, please contact @team-atlas.
Expand Down
11 changes: 2 additions & 9 deletions mimir/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ BRANCH="main"
MIXIN_URL=https://github.com/grafana/mimir/operations/mimir-mixin@$BRANCH
helmDir="$(pwd)/helm/dashboards/charts/private_dashboards_mz/dashboards/shared/private"

set -x
cd mimir
rm -rf vendor jsonnetfile.*

jb init
jb install $MIXIN_URL
mixtool generate dashboards mixin.libsonnet --directory=dashboards_out

for file in dashboards_out/*; do
# Process each file here
echo "$file"

echo "Copying dashboard to $helmDir"
cp "$file" "$helmDir"
done
mixtool generate dashboards mixin.libsonnet --directory=$helmDir
84 changes: 84 additions & 0 deletions scripts/install-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

set -eu

DASHBOARD_LINTER_VERSION="eb2bc3ba25e3f0ae816b45ed3d05700002f76871"
MIXTOOL_VERSION="448a81c91e517aa4259e7d3e039c19fed9771864"

JB_VERSION="v0.5.1"
JB_BIN="jb"

YQ_VERSION="v4.44.3"
YQ_BIN="yq"

SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
TOOLS_DIR="$SCRIPT_DIR/../tools"
OS=$(go env GOOS)
ARCH=$(go env GOARCH)
TMPDIR="$(mktemp -d -t giantswarm-dashboards-XXXXXX)"
trap "rm -rf $TMPDIR" EXIT

install_tool() {
# Sometimes the archive might contain a folder tree. Use this as a path prefix relative to the root of the
# extraction folder to point to the actual binary or pass it as empty string if the binary is directly downloaded.
local binaryPath=$1 ; shift
local binary=$1 ; shift
local version=$1 ; shift
local url=$1 ; shift

local short_path="${TOOLS_DIR}/${binary}"
local long_path="${short_path}-${version}"

file=$(basename "${url}")

if [[ ! -f "${long_path}" ]]; then
echo "---> Installing ${binary} ${version}"
set -x
curl -fsL -o "${TMPDIR}/${file}" "${url}"
{ set +x; } 2>/dev/null
if [[ "${file}" == *.tar.gz ]]; then
set -x
tar xf "${TMPDIR}/${file}" -C "${TMPDIR}" --strip-components 1
{ set +x; } 2>/dev/null
elif [[ "${file}" == *.zip ]]; then
set -x
unzip -qo "${TMPDIR}/${file}" -d "${TMPDIR}"
{ set +x; } 2>/dev/null
else
set -x
mv "${TMPDIR}/${file}" "${TMPDIR}/${binary}"
{ set +x; } 2>/dev/null
fi
set -x
chmod +x "${TMPDIR}/${binaryPath}${binary}"
mv "${TMPDIR}/${binaryPath}${binary}" "${long_path}"
{ set +x; } 2>/dev/null
base_long="$(basename "${long_path}")"
set -x
ln -fs "${base_long}" "${short_path}"
{ set +x; } 2>/dev/null
fi
}

go_install() {
url="$1"
binary=$(basename "$url")
version="$2"

if ! command -v "$binary" &>/dev/null; then
echo "---> Installing $binary"
go install "$1@$version"
fi
}

main() {
command -v go &>/dev/null || { echo "go is required but not installed"; exit 1; }

install_tool "" "${JB_BIN}" "${JB_VERSION}" "https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/${JB_VERSION}/jb-${OS}-${ARCH}"
install_tool "" "${YQ_BIN}" "${YQ_VERSION}" "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${OS}_${ARCH}"

go_install "github.com/monitoring-mixins/mixtool/cmd/mixtool" "$MIXTOOL_VERSION"
go_install "github.com/grafana/dashboard-linter" "$DASHBOARD_LINTER_VERSION"
}

main "$@"
24 changes: 24 additions & 0 deletions scripts/update-alloy-mixin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Update Alloy mixin dashboards
#
# This script updates the Alloy mixin dashboards from the upstream repository.
#
# Usage:
# ./update-alloy-mixin.sh

set -eu

SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
TOOLS_DIR="$SCRIPT_DIR/../tools"
TMPDIR="$(mktemp -d -t giantswarm-dashboards-XXXXXX)"
trap "rm -rf $TMPDIR" EXIT

alloy_mixin_dir="$TMPDIR/alloy/operations/alloy-mixin"
helm_dir="$SCRIPT_DIR/../helm/dashboards/charts/private_dashboards_al/dashboards/shared/private"

set -x
git clone https://github.com/grafana/alloy.git --depth 1 "$TMPDIR/alloy"
cd "$alloy_mixin_dir"
"$TOOLS_DIR/jb" install
mixtool generate dashboards mixin.libsonnet -d "$helm_dir"
Empty file added tools/.gitkeep
Empty file.