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

k8s-monitoring 2.0 alpha #757

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f3cbf82
Add cluster events feature chart and a new github action to test feat…
petewall Sep 30, 2024
647b173
Update test action
petewall Sep 30, 2024
4c9c162
Add a gitkeep to make the snapshot directory exist
petewall Sep 30, 2024
1ad2292
Add annotation feature chart
petewall Sep 30, 2024
753ddd4
Add cluster metrics feature
petewall Sep 30, 2024
a6a0618
Fix yaml lint
petewall Sep 30, 2024
de70c1f
Update linters and top-level makefile
petewall Oct 1, 2024
8b6fd31
More lint fixes
petewall Oct 1, 2024
0423ccf
Re-enable linting for test yamls
petewall Oct 1, 2024
56a7654
Make markdownlint happier
petewall Oct 1, 2024
746c1ab
Adding pod logs, profiling, and prom operator object feature charts
petewall Oct 1, 2024
9827964
remove -it from docker run
petewall Oct 1, 2024
d27ec5a
Update checkout action
petewall Oct 1, 2024
f00baa8
Simplify diff check
petewall Oct 1, 2024
4663de5
Add app o11y and frontend o11y feature charts
petewall Oct 1, 2024
def3112
Move codeowners into .github and break things down by directory
petewall Oct 1, 2024
91999f5
add integration feature
petewall Oct 1, 2024
37aced9
Don't delete Chart.lock, because it is not built deterministicly, sin…
petewall Oct 1, 2024
4110ff7
Sort the integration values so the order is deterministic
petewall Oct 1, 2024
3b45e6a
Add main chart
petewall Oct 1, 2024
47d7326
Fix linters
petewall Oct 1, 2024
c6309f2
Make lint-md do more and catch more changes
petewall Oct 1, 2024
b5e56ad
ct lint in every chart
petewall Oct 1, 2024
553b20c
legacy test should only work on the the v1 chart
petewall Oct 1, 2024
b6ccea9
Add ct to the github action
petewall Oct 1, 2024
0933bbb
add ct configs for charts that use dependenties
petewall Oct 1, 2024
5a27369
Include chart v2 in the chart test workflow
petewall Oct 1, 2024
e9b7dbb
Add clean target
petewall Oct 1, 2024
c61c4e7
Add file to make helm unittest work
petewall Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
16 changes: 16 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used to define the owners of the code in this repository.
# https://help.github.com/articles/about-codeowners/

# Global owners
* @petewall

# Chart owners
charts/feature-annotation-autodiscovery @grafana/k8s-monitoring-dev
charts/feature-application-observability @rlankfo
charts/feature-cluster-events @grafana/k8s-monitoring-dev
charts/feature-cluster-metrics @grafana/k8s-monitoring-dev
charts/feature-frontend-observability @rlankfo
charts/feature-pod-logs @grafana/k8s-monitoring-dev
charts/feature-profiling @simonswine
charts/feature-prometheus-operator-objects @grafana/k8s-monitoring-dev
charts/k8s-monitoring-v1 @grafana/k8s-monitoring-dev
4 changes: 2 additions & 2 deletions .github/workflows/helm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
CT_CONFIGFILE: "${{ github.workspace }}/.github/configs/ct.yaml"
LINT_CONFIGFILE: "${{ github.workspace }}/.github/configs/lintconf.yaml"
LINT_CONFIGFILE: "${{ github.workspace }}/.configs/lintconf.yaml"
GRAFANA_ALLOY_VALUES: "${{ github.workspace }}/.github/configs/alloy-config.yaml"
GRAFANA_ALLOY_LOKI_OTLP_VALUES: "${{ github.workspace }}/.github/configs/alloy-config-loki-otlp.yaml"
GRAFANA_ALLOY_RECEIVER_SERVICE: "${{ github.workspace }}/.github/configs/receiver-service.yaml"
Expand Down Expand Up @@ -212,4 +212,4 @@ jobs:
if: (steps.list-changed.outputs.changed == 'true') || (contains(github.event.pull_request.labels.*.name, 'full_test_required'))
run: |
latestRelease=$(git describe --abbrev=0 --tags)
ct install --all --config "${CT_CONFIGFILE}" --since "${latestRelease}" --helm-extra-args "--timeout 10m"
ct install --all --config "${CT_CONFIGFILE}" --since "${latestRelease}" --helm-extra-args "--timeout 10m" --charts "k8s-monitoring-v1"
8 changes: 6 additions & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
name: ReviewDog
# yamllint disable-line rule:truthy
on:
pull_request:
push:
branches: ["main"]

pull_request:

workflow_dispatch:

jobs:
markdownlint:
name: runner / markdownlint
Expand Down Expand Up @@ -137,7 +141,7 @@ jobs:
- env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx textlint --format checkstyle --config ./.textlintrc --ignore-path ./.textlintignore $(find . -type f -name "*.md" -not \( -path "./node_modules/*" -o -path "./data-alloy/*" \)) | \
npx textlint --format checkstyle --config ./.textlintrc --ignore-path ./.textlintignore "$(find . -type f -name "*.md" -not \( -path "./node_modules/*" -o -path "./data-alloy/*" \))" | \
reviewdog -f=checkstyle -name="textlint" -reporter=github-check -level=info

alloy:
Expand Down
119 changes: 119 additions & 0 deletions .github/workflows/test-charts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
name: Test Chart
# yamllint disable-line rule:truthy
on:
push:
branches: ["main"]
paths:
- 'charts/**'
- '!charts/k8s-monitoring-v1/**'
pull_request:
paths:
- 'charts/**'
- '!charts/k8s-monitoring-v1/**'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:


jobs:
detect-changed-charts:
name: Detect Changed Charts
runs-on: ubuntu-latest
outputs:
changed_charts: ${{ steps.changed_charts.outputs.changed_charts }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect Changed Charts
id: changed_charts
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# In pull request, compare against the base branch (upstream)
base_branch="${{ github.event.pull_request.base.ref }}"
echo "Comparing against base branch: $base_branch"
git fetch origin $base_branch
base_commit="origin/$base_branch"
elif [ "${{ github.event_name }}" == "push" ]; then
# In push to main, compare the last commit with HEAD^
base_commit="HEAD^"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# In manual trigger, run for all charts
echo "Manual dispatch detected, running tests for all charts"
# shellcheck disable=SC2010
echo "changed_charts=$(ls charts | grep -v "k8s-monitoring-v1" | sort -u)" >> "${GITHUB_OUTPUT}"
exit 0
fi

# Check if base commit exists, fallback to empty tree if none
if ! git rev-parse --verify "$base_commit" >/dev/null 2>&1; then
base_commit=$(git hash-object -t tree /dev/null)
fi

# Detect modified files
modified_charts=$(git diff --name-only "$base_commit" HEAD -- 'charts/*' | grep "^charts/" | cut -d "/" -f2 | sort -u)

# Detect newly added files (untracked files)
added_charts=$(git ls-files --others --exclude-standard -- 'charts/*' | grep "^charts/" | cut -d "/" -f2 | sort -u)

# Combine both added and modified charts
changed_charts=$(echo -e "$modified_charts\n$added_charts" | grep -v "k8s-monitoring-v1" | sort -u)

if [ -z "$changed_charts" ]; then
echo "No changes detected in charts"
changed_charts="none"
fi
echo "Changed charts: $changed_charts"
echo "changed_charts=$(echo "$changed_charts" | jq --raw-input --slurp --compact-output 'split("\n") | map(select(. != ""))')" >> "${GITHUB_OUTPUT}"

run-tests:
name: Testing
needs: detect-changed-charts
runs-on: ubuntu-latest
strategy:
matrix:
dir: ${{ fromJson(needs.detect-changed-charts.outputs.changed_charts) }}
fail-fast: false
if: ${{ needs.detect-changed-charts.outputs.changed_charts != 'none' }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up chart-testing
uses: helm/chart-testing-action@v2

- name: Run tests
run: |
echo "Testing ${{ matrix.dir }}"
cd charts/${{ matrix.dir }}
make test

check-generated-files:
name: Check Generated Files
needs: detect-changed-charts
runs-on: ubuntu-latest
strategy:
matrix:
dir: ${{ fromJson(needs.detect-changed-charts.outputs.changed_charts) }}
fail-fast: false
if: ${{ needs.detect-changed-charts.outputs.changed_charts != 'none' }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Regenerate files
run: |
echo "Running make all in charts/${{ matrix.dir }}"
cd charts/${{ matrix.dir }}
make clean build

- name: Check for changes in generated files
run: |
cd charts/${{ matrix.dir }}
if ! git diff --exit-code .; then
echo "Generated files in charts/${{ matrix.dir }} are not up to date. Please run 'make all' and commit the changes."
exit 1
else
echo "Generated files in charts/${{ matrix.dir }} are up to date."
fi
1 change: 1 addition & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ignore:
- .git
- data-alloy
- node_modules
- charts/k8s-monitoring/docs/examples/**/output.yaml
- charts/k8s-monitoring-v1/docs/examples/**/output.yaml
- charts/**/templates

Expand Down
7 changes: 0 additions & 7 deletions CODEOWNERS

This file was deleted.

31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
.PHONY: setup install lint lint-chart lint-config lint-configs lint-alloy lint-sh lint-md lint-txt lint-yml lint-ec lint-alex lint-misspell lint-actionlint test install-deps clean
SHELL := /bin/bash
UNAME := $(shell uname)

CT_CONFIGFILE ?= .github/configs/ct.yaml
LINT_CONFIGFILE ?= .github/configs/lintconf.yaml
FEATURE_CHARTS = $(shell ls charts | grep -v k8s-monitoring)

.PHONY: build
build:
set -e && \
for chart in $(FEATURE_CHARTS); do \
make -C charts/$$chart build; \
done
make -C charts/k8s-monitoring build

.PHONY: test
test: build
set -e && \
for chart in $(FEATURE_CHARTS); do \
make -C charts/$$chart test; \
done
make -C charts/k8s-monitoring test

####################################################################
# Installation / Setup #
####################################################################
.PHONY: setup install-deps
setup install-deps:
ifeq ($(UNAME), Darwin)
@./scripts/setup.sh
Expand All @@ -16,22 +31,22 @@ else
exit 1
endif

.PHONY: install
install:
yarn install

.PHONY: clean
clean:
rm -rf node_modules

####################################################################
# Linting #
####################################################################
lint: lint-chart lint-config lint-sh lint-md lint-txt lint-yml lint-ec lint-alex lint-misspell lint-actionlint
.PHONY: lint lint-chart lint-sh lint-md lint-txt lint-yml lint-ec lint-alex lint-misspell lint-actionlint
lint: lint-chart lint-sh lint-md lint-txt lint-yml lint-ec lint-alex lint-misspell lint-actionlint

lint-chart:
ct lint --debug --config "$(CT_CONFIGFILE)" --lint-conf "$(LINT_CONFIGFILE)" --check-version-increment=false

lint-config lint-configs lint-alloy:
@./scripts/lint-alloy.sh $(METRICS_CONFIG_FILES) $(EVENTS_CONFIG_FILES) $(LOGS_CONFIG_FILES) --public-preview $(PROFILES_CONFIG_FILES)
ct lint --debug --lint-conf .configs/lintconf.yaml --check-version-increment=false

# Shell Linting
lint-sh lint-shell:
Expand Down
6 changes: 6 additions & 0 deletions charts/feature-annotation-autodiscovery/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docs
schema-mods
tests
Makefile
README.md
README.md.gotmpl
3 changes: 3 additions & 0 deletions charts/feature-annotation-autodiscovery/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies: []
digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726
generated: "2024-09-25T13:45:54.706765-05:00"
11 changes: 11 additions & 0 deletions charts/feature-annotation-autodiscovery/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: v2
name: k8s-monitoring-feature-annotation-autodiscovery
description: Gathers metrics automatically based on Kubernetes Pod and Service annotations
icon: https://raw.githubusercontent.com/grafana/grafana/main/public/img/grafana_icon.svg
version: 1.0.0
appVersion: 1.0.0
maintainers:
- email: pete.wall@grafana.com
name: petewall
dependencies: []
34 changes: 34 additions & 0 deletions charts/feature-annotation-autodiscovery/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
HAS_HELM_DOCS := $(shell command -v helm-docs;)
HAS_HELM_UNITTEST := $(shell helm plugin list | grep unittest 2> /dev/null)

.SECONDEXPANSION:
README.md: values.yaml Chart.yaml $$(wildcard README.md.gotmpl)
ifdef HAS_HELM_DOCS
helm-docs
else
docker run --rm --volume "$(shell pwd):/helm-docs" -u $(shell id -u) jnorwood/helm-docs:latest
endif

Chart.lock: Chart.yaml
helm dependency update .
@touch Chart.lock # Ensure the timestamp is updated

values.schema.json: values.yaml $$(wildcard schema-mods/*)
../../scripts/schema-gen.sh .

.PHONY: clean
clean:
rm -f README.md values.schema.json

.PHONY: build
build: README.md Chart.lock values.schema.json

.PHONY: test
test: build
helm lint .
ct lint --lint-conf ../../.configs/lintconf.yaml --check-version-increment=false --charts .
ifdef HAS_HELM_UNITTEST
helm unittest .
else
docker run --rm --volume $(shell pwd):/apps helmunittest/helm-unittest .
endif
65 changes: 65 additions & 0 deletions charts/feature-annotation-autodiscovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# k8s-monitoring-feature-annotation-autodiscovery

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square)

Gathers metrics automatically based on Kubernetes Pod and Service annotations

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| petewall | <pete.wall@grafana.com> | |

## Values

### Annotations

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| annotations.instance | string | `"k8s.grafana.com/instance"` | Annotation for overriding the instance label |
| annotations.job | string | `"k8s.grafana.com/job"` | Annotation for overriding the job label |
| annotations.metricsPath | string | `"k8s.grafana.com/metrics.path"` | Annotation for setting or overriding the metrics path. If not set, it defaults to /metrics |
| annotations.metricsPortName | string | `"k8s.grafana.com/metrics.portName"` | Annotation for setting the metrics port by name. |
| annotations.metricsPortNumber | string | `"k8s.grafana.com/metrics.portNumber"` | Annotation for setting the metrics port by number. |
| annotations.metricsScheme | string | `"k8s.grafana.com/metrics.scheme"` | Annotation for setting the metrics scheme, default: http. |
| annotations.metricsScrapeInterval | string | `"k8s.grafana.com/metrics.scrapeInterval"` | Annotation for overriding the scrape interval for this service or pod. Value should be a duration like "15s, 1m". Overrides metrics.autoDiscover.scrapeInterval |
| annotations.scrape | string | `"k8s.grafana.com/scrape"` | Annotation for enabling scraping for this service or pod. Value should be either "true" or "false" |

### Scrape Settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| bearerToken | object | `{"enabled":true,"token":"/var/run/secrets/kubernetes.io/serviceaccount/token"}` | Sets bearer_token_file line in the prometheus.scrape annotation_autodiscovery. |
| scrapeInterval | string | 60s | How frequently to scrape metrics from PodMonitor objects. Only used if the PodMonitor does not specify the scrape interval. Overrides global.scrapeInterval |

### Discovery Settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| extraDiscoveryRules | string | `""` | Rule blocks to be added to the prometheus.operator.podmonitors component for PodMonitors. These relabeling rules are applied pre-scrape against the targets from service discovery. The relabelings defined in the PodMonitor object are applied first, then these relabelings are applied. Before the scrape, any remaining target labels that start with `__` (i.e. `__meta_kubernetes*`) are dropped. ([docs](https://grafana.com/docs/alloy/latest/reference/components/discovery.relabel/#rule-block)) |

### Metric Processing Settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| extraMetricProcessingRules | string | `""` | Rule blocks to be added to the prometheus.relabel component for PodMonitor objects. These relabeling rules are applied post-scrape against the metrics returned from the scraped target, no `__meta*` labels are present. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#rule-block)) |
| maxCacheSize | string | `nil` | Sets the max_cache_size for cadvisor prometheus.relabel component. This should be at least 2x-5x your largest scrape target or samples appended rate. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) Overrides global.maxCacheSize |
| metricsTuning.excludeMetrics | list | `[]` | Metrics to drop. Can use regular expressions. |
| metricsTuning.includeMetrics | list | `[]` | Metrics to keep. Can use regular expressions. |

### General settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| fullnameOverride | string | `""` | Full name override |
| nameOverride | string | `""` | Name override |

### Global Settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| global.maxCacheSize | int | `100000` | Sets the max_cache_size for every prometheus.relabel component. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) This should be at least 2x-5x your largest scrape target or samples appended rate. |
| global.scrapeInterval | string | `"60s"` | How frequently to scrape metrics. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)
Loading
Loading