Skip to content

Commit

Permalink
ci: always release chart (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis authored Sep 8, 2023
1 parent 3531fc0 commit 6e5f853
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 165 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request,
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
# Once installed, if the workflow run is marked as required,
# PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
name: 'Dependency Review'
name: dependency_review
on: [pull_request]

permissions:
Expand Down
121 changes: 113 additions & 8 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@ on:
permissions: {}

jobs:
build:
lint-chart:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5
with:
version: v3.4.0

- uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0

- name: Run chart-testing (lint)
run: ct lint --target-branch=master --chart-dirs chart --check-version-increment=false

lint:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
Expand All @@ -37,6 +65,35 @@ jobs:
run: make vet
- name: lint
run: make lint
- name: Check if working tree is dirty
run: |
if [[ $(git diff --stat) != '' ]]; then
git --no-pager diff
echo 'run make test and commit changes'
exit 1
fi
build:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- name: Setup Go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: 1.20.5
- name: Restore Go cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
run: make test
- name: Build binary
Expand All @@ -45,13 +102,6 @@ jobs:
uses: shogo82148/actions-goveralls@df920a6a2468668dfcf71a0b43817f89eaa5ea04 # v1.7.0
with:
path-to-profile: coverage.out
- name: Check if working tree is dirty
run: |
if [[ $(git diff --stat) != '' ]]; then
git --no-pager diff
echo 'run make test and commit changes'
exit 1
fi
- name: Build container image
run: |
make docker-build
Expand All @@ -69,6 +119,61 @@ jobs:
profiles=$(ls config/tests/cases | jq -R -s -c 'split("\n")[:-1]')
echo $profiles
echo "::set-output name=matrix::$profiles"
test-chart:
runs-on: ubuntu-latest
needs:
- build
- lint-chart
steps:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5
with:
version: v3.4.0

- uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch=master --chart-dirs chart)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Create kind cluster
uses: helm/kind-action@fa81e57adff234b2908110485695db0f181f3c67 # v1.7.0
if: steps.list-changed.outputs.changed == 'true'

- name: Download exporter container
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: exporter-container
path: /tmp
- name: Load image
run: |
docker load --input /tmp/exporter-container.tar
docker tag ghcr.io/raffis/mongodb-query-exporter:latest ghcr.io/raffis/mongodb-query-exporter:0.0.0
docker image ls -a
kind load docker-image ghcr.io/raffis/mongodb-query-exporter:0.0.0 --name chart-testing
- name: Run chart-testing (install)
run: ct install --target-branch=master --chart-dirs chart

e2e-tests:
runs-on: ubuntu-latest
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/pr-chart.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/release-chart.yaml

This file was deleted.

42 changes: 40 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
permissions: {}

jobs:
build:
name: Build
release:
runs-on: ubuntu-latest
permissions:
contents: write # needed to write releases
Expand Down Expand Up @@ -44,3 +43,42 @@ jobs:
args: release --rm-dist --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release-chart:
runs-on: ubuntu-latest
needs:
- release
permissions:
packages: write # Needed to publish chart to ghcr.io
id-token: write # Needed for keyless signing
steps:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
with:
fetch-depth: 0

- name: Install Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5

- name: Setup Cosign
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1

- name: Login to Github Container Registry using helm
run: echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin

- name: Package helm charts
run: |
packVersion=$(echo "${{ github.ref_name }}" | sed 's/^v//g')
helm package chart/mongodb-query-exporter -d chart --version=$packVersion --app-version=${{ github.ref_name }}
- name: Publish helm charts to Github Container Registry
run: |
repository=$(echo "${{ github.repository_owner }}" | tr [:upper:] [:lower:])
helm push ${{ github.workspace }}/chart/mongodb-query-exporter-*.tgz oci://ghcr.io/$repository/charts |& tee .digest
cosign login --username ${GITHUB_ACTOR} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io
cosign sign --yes ghcr.io/${{ github.repository_owner }}/charts/mongodb-query-exporter@$(cat .digest | awk -F "[, ]+" '/Digest/{print $NF}')
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prometheus MongoDB query exporter
[![release](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml/badge.svg)](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v3)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v3)
[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v5)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v5)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/raffis/mongodb-query-exporter/badge)](https://api.securityscorecards.dev/projects/github.com/raffis/mongodb-query-exporter)
[![Coverage Status](https://coveralls.io/repos/github/raffis/mongodb-query-exporter/badge.svg?branch=master)](https://coveralls.io/github/raffis/mongodb-query-exporter?branch=master)
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/mongodb-query-exporter)](https://artifacthub.io/packages/search?repo=mongodb-query-exporter)
Expand Down Expand Up @@ -138,7 +138,8 @@ aggregations:
overrideEmpty: true # if an empty result set is returned..
emptyValue: 0 # create a metric with value 0
labels: []
constLabels: []
constLabels:
region: eu-central-1
cache: 0
mode: pull
pipeline: |
Expand All @@ -153,7 +154,7 @@ aggregations:
help: 'The total number of processes in a job queue'
value: total
labels: [type,status]
constLabels: []
constLabels: {}
mode: pull
pipeline: |
[
Expand Down Expand Up @@ -188,7 +189,7 @@ aggregations:
help: 'The total number of events (created 1h ago or newer)'
value: count
labels: [type]
constLabels: []
constLabels: {}
mode: pull
# Note $$NOW is only supported in MongoDB >= 4.2
pipeline: |
Expand Down
4 changes: 2 additions & 2 deletions chart/mongodb-query-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
appVersion: 2.0.3
appVersion: 0.0.0
description: A Prometheus exporter for MongoDB custom aggregations
home: https://github.com/raffis/mongodb-query-exporter
maintainers:
Expand All @@ -15,4 +15,4 @@ keywords:
name: mongodb-query-exporter
sources:
- https://github.com/raffis/mongodb-query-exporter
version: 4.0.3
version: 0.0.0
8 changes: 1 addition & 7 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ type integrationTest struct {

func TestMetricsConfigv2(t *testing.T) {
expected := map[string]string{
"myapp_example_simplevalue_total": `name:"myapp_example_simplevalue_total" help:"Simple gauge metric" type:GAUGE metric:<label:<name:"server" value:"main" > gauge:<value:2 > > `,
"myapp_example_simplevalue_total": `name:"myapp_example_simplevalue_total" help:"Simple gauge metric" type:GAUGE metric:<label:<name:"region" value:"eu-central-1" > label:<name:"server" value:"main" > gauge:<value:2 > > `,
"myapp_example_processes_total": `name:"myapp_example_processes_total" help:"The total number of processes in a job queue" type:GAUGE metric:<label:<name:"server" value:"main" > label:<name:"status" value:"postponed" > label:<name:"type" value:"foobar" > gauge:<value:2 > > metric:<label:<name:"server" value:"main" > label:<name:"status" value:"processing" > label:<name:"type" value:"bar" > gauge:<value:1 > > `,
"myapp_events_total": `name:"myapp_events_total" help:"The total number of events (created 1h ago or newer)" type:GAUGE metric:<label:<name:"server" value:"main" > label:<name:"type" value:"bar" > gauge:<value:2 > > metric:<label:<name:"server" value:"main" > label:<name:"type" value:"foo" > gauge:<value:1 > > `,
"mongodb_query_exporter_query_total": `name:"mongodb_query_exporter_query_total" help:"How many MongoDB queries have been processed, partitioned by metric, server and status" type:COUNTER metric:<label:<name:"aggregation" value:"aggregation_0" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > metric:<label:<name:"aggregation" value:"aggregation_1" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > metric:<label:<name:"aggregation" value:"aggregation_2" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > `,
}

tests := []integrationTest{
/*integrationTest{
name: "integration test using config v1.0 and mongodb:5.0",
configPath: "../example/configv1.yaml",
mongodbImage: "mongo:5.0",
expectedMetrics: expected,
},*/
{
name: "integration test using config v2.0 and mongodb:5.0",
configPath: "../example/configv2.yaml",
Expand Down
10 changes: 5 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"os/user"
"time"

"github.com/raffis/mongodb-query-exporter/v3/internal/collector"
"github.com/raffis/mongodb-query-exporter/v3/internal/config"
v1 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v1"
v2 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v2"
v3 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v3"
"github.com/raffis/mongodb-query-exporter/v5/internal/collector"
"github.com/raffis/mongodb-query-exporter/v5/internal/config"
v1 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v1"
v2 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v2"
v3 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v3"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down
Loading

0 comments on commit 6e5f853

Please sign in to comment.