From 1fe1ac3cfe72d0b6bcdcc6e6631d8af327ce197a Mon Sep 17 00:00:00 2001 From: SeamusGrafana <102023327+SeamusGrafana@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:19:07 +0000 Subject: [PATCH 01/12] Add Native Histogram Metrics --- pkg/http/http.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/http/http.go b/pkg/http/http.go index b339f770..6dbc5017 100644 --- a/pkg/http/http.go +++ b/pkg/http/http.go @@ -51,12 +51,28 @@ var ( Buckets: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }) + numberOfIngredientsPerPizzaNativeHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ + Name: "number_of_ingredients_per_pizza_alternate", + Help: "The number of ingredients per pizza (Native Histogram)", + NativeHistogramBucketFactor: 1.1, + NativeHistogramMaxBucketNumber: 100, + NativeHistogramMinResetDuration: 1 * time.Hour, + }) + pizzaCaloriesPerSlice = promauto.NewHistogram(prometheus.HistogramOpts{ Name: "pizza_calories_per_slice", Help: "The number of calories per slice of pizza", Buckets: []float64{100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000}, }) + pizzaCaloriesPerSliceNativeHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ + Name: "pizza_calories_per_slice_alternate", + Help: "The number of calories per slice of pizza (Native Histogram)", + NativeHistogramBucketFactor: 1.1, + NativeHistogramMaxBucketNumber: 100, + NativeHistogramMinResetDuration: 1 * time.Hour, + }) + httpRequests = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "http_requests_total", Help: "The total number of HTTP requests", @@ -703,7 +719,9 @@ func (s *Server) WithRecommendations(catalogClient CatalogClient, copyClient Cop }).Inc() numberOfIngredientsPerPizza.Observe(float64(len(p.Ingredients))) + numberOfIngredientsPerPizzaNativeHistogram.Observe(float64(len(p.Ingredients))) pizzaCaloriesPerSlice.Observe(float64(pizzaRecommendation.Calories)) + pizzaCaloriesPerSliceNativeHistogram.Observe(float64(pizzaRecommendation.Calories)) s.log.InfoContext(r.Context(), "New pizza recommendation", "pizza", pizzaRecommendation.Pizza.Name) From e34cd6723d48beae1d92fda5fc648e497b6d8cef Mon Sep 17 00:00:00 2001 From: SeamusGrafana <102023327+SeamusGrafana@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:52:39 +0000 Subject: [PATCH 02/12] [chore] - Add Dependabot Config to Bump Package Dependencies --- .github/dependabot.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..a6107ab7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 + commit-message: + prefix: "chore(deps): " + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + commit-message: + prefix: "chore(deps): " + - package-ecosystem: 'npm' + directory: '/pkg/web/' + schedule: + interval: 'daily' + open-pull-requests-limit: 10 + commit-message: + prefix: "chore(deps): " From ebe189a56673f6cba735238b202fa5407a8dce80 Mon Sep 17 00:00:00 2001 From: SeamusGrafana <102023327+SeamusGrafana@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:45:54 +0000 Subject: [PATCH 03/12] Add Config for Docker --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a6107ab7..8e4d6e6f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,12 @@ version: 2 updates: + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 + commit-message: + prefix: "chore(deps): " - package-ecosystem: "github-actions" directory: "/" schedule: From 4405a1b839b9569263f5420759ac29b64fa410d0 Mon Sep 17 00:00:00 2001 From: SeamusGrafana <102023327+SeamusGrafana@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:16:51 +0000 Subject: [PATCH 04/12] Allow specifying Custom Base URL in gRPC Test Script --- k6/foundations/16.grpc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k6/foundations/16.grpc.js b/k6/foundations/16.grpc.js index 18b64b93..2f188197 100644 --- a/k6/foundations/16.grpc.js +++ b/k6/foundations/16.grpc.js @@ -1,7 +1,7 @@ import { Client, StatusOK } from 'k6/net/grpc'; import { check, sleep } from 'k6'; -const BASE_URL = 'localhost:3334'; +const BASE_URL = __ENV.BASE_URL || 'http://localhost:3334'; const client = new Client(); client.load(['definitions'], '../../../proto/quickpizza.proto'); From 5021211a88e1f97caa0a6418fe3e0c0c321515e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:00:23 +0000 Subject: [PATCH 05/12] chore(deps): bump docker/login-action from 1 to 3 Bumps [docker/login-action](https://github.com/docker/login-action) from 1 to 3. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v1...v3) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 9bf0692b..f2b9d3ed 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Login to the registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} From 54374f2a4cd3a484e3f61a7d008f8bb2b3151b1e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:00:25 +0000 Subject: [PATCH 06/12] chore(deps): bump actions/cache from 3 to 4 Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/k6-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/k6-tests.yaml b/.github/workflows/k6-tests.yaml index 193c4bbc..49b09f6c 100644 --- a/.github/workflows/k6-tests.yaml +++ b/.github/workflows/k6-tests.yaml @@ -22,7 +22,7 @@ jobs: - name: Cache k6 id: cache-k6 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /usr/bin/k6 key: ${{ runner.os }}-k6 From 48fe29b9c421051fe03fd6e330e57fcc67ed4b4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:00:28 +0000 Subject: [PATCH 07/12] chore(deps): bump actions/github-script from 6 to 7 Bumps [actions/github-script](https://github.com/actions/github-script) from 6 to 7. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/github-script dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 9bf0692b..93064892 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -20,7 +20,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Set version - uses: actions/github-script@v6 + uses: actions/github-script@v7 id: set_version with: script: | From 30f3caf0c402acddd8d8abb5df4119fceab64699 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:00:31 +0000 Subject: [PATCH 08/12] chore(deps): bump docker/build-push-action from 5 to 6 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5...v6) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 9bf0692b..a78f9b1c 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -29,7 +29,7 @@ jobs: core.setOutput('tag', tag) core.setOutput('tag-no-v', tag_no_v) - name: Build Docker image and push to the Registry - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile From 60bdd3c9b962c69b67ce8611e75b139074dade6a Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Fri, 13 Dec 2024 11:15:37 +0100 Subject: [PATCH 09/12] Add build workflow --- .github/workflows/build.yaml | 19 +++++++++++++++++++ Makefile | 18 ++++++++++-------- pkg/http/http.go | 4 ++-- pkg/web/web.go | 2 ++ pkg/web/web_mock.go | 10 ++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 pkg/web/web_mock.go diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..2a2ca581 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,19 @@ +name: k6 - Test Suite +on: [push] + +jobs: + runner-job: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + + - name: Check Formatting + run: make format-check + + - name: Build Binary + run: make build diff --git a/Makefile b/Makefile index a3a72819..6aa3937b 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,9 @@ GO_SOURCES=$(shell find . -type f -name '*.go' -not -path "./vendor/*") -.PHONY: run -run: - go generate pkg/web/web.go - CGO_ENABLED=0 go run ./cmd - -# TODO: add build recipe for npm +# Note: does not include frontend files, only Go code. .PHONY: build build: - go generate pkg/web/web.go - CGO_ENABLED=0 go build -o bin/quickpizza ./cmd + go build -tags=mock -o bin/quickpizza ./cmd .PHONY: proto proto: @@ -22,3 +16,11 @@ format: .PHONY: format-check format-check: @out=$$(goimports -l $(GO_SOURCES)) && echo "$$out" && test -z "$$out" + +.PHONY: docker-localdev-build +docker-localdev-build: + docker build . -t grafana/quickpizza:localdev + +.PHONY: docker-localdev-run +docker-localdev-run: + docker run --rm -it -p 3333:3333 -p 3334:3334 -p 3335:3335 -v $$(pwd):/db -e QUICKPIZZA_DB=file:/db/quickpizza.db grafana/quickpizza:localdev diff --git a/pkg/http/http.go b/pkg/http/http.go index 6dbc5017..8fc54aa1 100644 --- a/pkg/http/http.go +++ b/pkg/http/http.go @@ -66,8 +66,8 @@ var ( }) pizzaCaloriesPerSliceNativeHistogram = promauto.NewHistogram(prometheus.HistogramOpts{ - Name: "pizza_calories_per_slice_alternate", - Help: "The number of calories per slice of pizza (Native Histogram)", + Name: "pizza_calories_per_slice_alternate", + Help: "The number of calories per slice of pizza (Native Histogram)", NativeHistogramBucketFactor: 1.1, NativeHistogramMaxBucketNumber: 100, NativeHistogramMinResetDuration: 1 * time.Hour, diff --git a/pkg/web/web.go b/pkg/web/web.go index c7c34cd5..b4fe2aae 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -1,3 +1,5 @@ +//go:build !mock + package web import "embed" diff --git a/pkg/web/web_mock.go b/pkg/web/web_mock.go new file mode 100644 index 00000000..3ee6d8d8 --- /dev/null +++ b/pkg/web/web_mock.go @@ -0,0 +1,10 @@ +//go:build mock + +package web + +import "embed" + +// Embed some random directory. +// +//go:embed all:static +var EmbeddedFiles embed.FS From aa645249955d948f2966a54e2e14cb23614a3787 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Fri, 13 Dec 2024 11:17:19 +0100 Subject: [PATCH 10/12] Fix workflow --- .github/workflows/build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2a2ca581..3c762acd 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,6 +12,9 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 + - name: Setup Goimports + run: go install golang.org/x/tools/cmd/goimports@latest + - name: Check Formatting run: make format-check From 92356efe5c5bd37a57c6761953019c9a63155b6c Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Fri, 13 Dec 2024 11:19:06 +0100 Subject: [PATCH 11/12] Update titles --- .github/workflows/build.yaml | 2 +- .github/workflows/docker.yaml | 2 +- .github/workflows/k6-tests.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3c762acd..e48d275d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: k6 - Test Suite +name: Check Formatting & Build on: [push] jobs: diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 6a6b83b3..094a5aee 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,4 +1,4 @@ -name: Build and push Docker images +name: Build and Push Docker Images on: release: types: diff --git a/.github/workflows/k6-tests.yaml b/.github/workflows/k6-tests.yaml index 49b09f6c..c3e4500e 100644 --- a/.github/workflows/k6-tests.yaml +++ b/.github/workflows/k6-tests.yaml @@ -1,4 +1,4 @@ -name: k6 - Test Suite +name: Run k6 Test Suite on: [push] jobs: From 73eb7fd68c0ea564692146c2b7609de354588aa5 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Fri, 13 Dec 2024 11:30:27 +0100 Subject: [PATCH 12/12] Adjust k6 test suite conditions --- .github/workflows/k6-tests.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/k6-tests.yaml b/.github/workflows/k6-tests.yaml index c3e4500e..dec8dbf0 100644 --- a/.github/workflows/k6-tests.yaml +++ b/.github/workflows/k6-tests.yaml @@ -1,5 +1,17 @@ name: Run k6 Test Suite -on: [push] +on: + push: + paths: + - 'scripts/**' + - 'k6/**' + release: + types: + - created + +# Important: The k6 test suite will only be run against the latest +# release of the Quickpizza service, not against the code in the +# commit itself. Therefore, we only run this Action when the test +# files themselves are modified (or on a new release). jobs: runner-job: