Skip to content

Commit 8687feb

Browse files
authored
feat: Add build reference to the info metrics (#817)
The reference will be from `_PULL_BASE_REF` variable from the cloud build: https://docs.prow.k8s.io/docs/jobs/ The change also fixes the commit label by using the right variable added in https://github.com/kubernetes/test-infra/pull/34755/files.
1 parent 519bee8 commit 8687feb

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ENV CGO_ENABLED=0
99
ENV GOOS=linux
1010
ENV GOARCH=amd64
1111
ARG COMMIT_SHA=unknown
12+
ARG BUILD_REF
1213

1314
# Dependencies
1415
WORKDIR /src
@@ -21,7 +22,7 @@ COPY pkg/epp ./pkg/epp
2122
COPY internal ./internal
2223
COPY api ./api
2324
WORKDIR /src/cmd
24-
RUN go build -ldflags="-X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.CommitSHA=${COMMIT_SHA}" -o /epp
25+
RUN go build -ldflags="-X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.CommitSHA=${COMMIT_SHA} -X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.BuildRef=${BUILD_REF}" -o /epp
2526

2627
## Multistage deploy
2728
FROM ${BASE_IMAGE}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ ifdef GO_VERSION
5151
BUILDER_IMAGE = golang:$(GO_VERSION)
5252
endif
5353

54+
BUILD_REF ?= $(shell git describe --abbrev=0 2>/dev/null)
5455
ifdef EXTRA_TAG
5556
IMAGE_EXTRA_TAG ?= $(IMAGE_REPO):$(EXTRA_TAG)
5657
SYNCER_IMAGE_EXTRA_TAG ?= $(SYNCER_IMAGE_REPO):$(EXTRA_TAG)
5758
BBR_IMAGE_EXTRA_TAG ?= $(BBR_IMAGE_REPO):$(EXTRA_TAG)
59+
BUILD_REF = $(EXTRA_TAG)
5860
endif
5961
ifdef IMAGE_EXTRA_TAG
6062
IMAGE_BUILD_EXTRA_OPTS += -t $(IMAGE_EXTRA_TAG)
@@ -177,6 +179,7 @@ image-build: ## Build the EPP image using Docker Buildx.
177179
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
178180
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
179181
--build-arg COMMIT_SHA=${GIT_COMMIT_SHA} \
182+
--build-arg BUILD_REF=${BUILD_REF} \
180183
$(PUSH) \
181184
$(LOAD) \
182185
$(IMAGE_BUILD_EXTRA_OPTS) ./

cloudbuild.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ steps:
1212
- GIT_TAG=$_GIT_TAG
1313
- EXTRA_TAG=$_PULL_BASE_REF
1414
- DOCKER_BUILDX_CMD=/buildx-entrypoint
15-
- GIT_COMMIT_SHA=$COMMIT_SHA
15+
- GIT_COMMIT_SHA=$_PULL_BASE_SHA
1616
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20240718-5ef92b5c36
1717
entrypoint: make
1818
args:
@@ -44,5 +44,7 @@ substitutions:
4444
# _PULL_BASE_REF will contain the ref that was pushed to trigger this build -
4545
# a branch like 'main' or 'release-0.2', or a tag like 'v0.2'.
4646
_PULL_BASE_REF: 'main'
47+
# _PULL_BASE_SHA will contain the Git SHA of the commit that was pushed to trigger this build.
48+
_PULL_BASE_SHA: 'abcdef'
4749
options:
4850
substitution_option: ALLOW_LOOSE

pkg/epp/metrics/metrics.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const (
3636
var (
3737
// The git hash of the latest commit in the build.
3838
CommitSHA string
39+
40+
// The build ref from the _PULL_BASE_REF from cloud build trigger.
41+
BuildRef string
3942
)
4043

4144
var (
@@ -251,7 +254,7 @@ var (
251254
Help: "General information of the current build of Inference Extension.",
252255
StabilityLevel: compbasemetrics.ALPHA,
253256
},
254-
[]string{"commit"},
257+
[]string{"commit", "build_ref"},
255258
)
256259
)
257260

@@ -409,7 +412,5 @@ func RecordPrefixCacheMatch(matchedLength, totalLength int) {
409412
}
410413

411414
func RecordInferenceExtensionInfo() {
412-
if CommitSHA != "" {
413-
InferenceExtensionInfo.WithLabelValues(CommitSHA).Set(1)
414-
}
415+
InferenceExtensionInfo.WithLabelValues(CommitSHA, BuildRef).Set(1)
415416
}

site-src/guides/metrics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ curl -i ${IP}:${PORT}/v1/completions -H 'Content-Type: application/json' -d '{
3434
| inference_model_running_requests | Gauge | Number of running requests for each model. | `model_name`=<model-name> | ALPHA |
3535
| inference_pool_average_kv_cache_utilization | Gauge | The average kv cache utilization for an inference server pool. | `name`=<inference-pool-name> | ALPHA |
3636
| inference_pool_average_queue_size | Gauge | The average number of requests pending in the model server queue. | `name`=<inference-pool-name> | ALPHA |
37-
| inference_pool_per_pod_queue_size | Gauge | The total number of queue for each model server pod under the inference pool | `model_server_pod`=<model-server-pod-name> `name`=<inference-pool-name> | ALPHA |
37+
| inference_pool_per_pod_queue_size | Gauge | The total number of queue for each model server pod under the inference pool | `model_server_pod`=&lt;model-server-pod-name&gt; <br> `name`=&lt;inference-pool-name&gt; | ALPHA |
3838
| inference_pool_ready_pods | Gauge | The number of ready pods for an inference server pool. | `name`=&lt;inference-pool-name&gt; | ALPHA |
39-
| inference_extension_info | Gauge | The general information of the current build. | `commit`=&lt;hash-of-the-build&gt; | ALPHA |
39+
| inference_extension_info | Gauge | The general information of the current build. | `commit`=&lt;hash-of-the-build&gt; <br> `build_ref`=&lt;ref-to-the-build&gt; | ALPHA |
4040

4141

4242
## Scrape Metrics

0 commit comments

Comments
 (0)