Skip to content

Commit 1874e21

Browse files
feat: add custommetrics cron for SLO monitoring (#4288)
Since it's seemingly impossible to compute this in GCP, add a `custommetrics` cronjob to compute time since last export as a metric to use as an SLO policy. Also, added missing resource/request limits to the recoverer and updated exporter's cronLastSuccessfulTimeMins to 30. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5080bec commit 1874e21

File tree

12 files changed

+232
-5
lines changed

12 files changed

+232
-5
lines changed

deployment/build-and-stage.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ steps:
9898
args: ['push', '--all-tags', 'gcr.io/oss-vdb/recoverer']
9999
waitFor: ['build-recoverer', 'cloud-build-queue']
100100

101-
# Build/push exporter/record-checker go images
101+
# Build/push go images
102102
- name: 'gcr.io/cloud-builders/docker'
103103
entrypoint: 'bash'
104104
args: ['-c', 'docker pull gcr.io/oss-vdb/exporter:latest || exit 0']
@@ -127,6 +127,20 @@ steps:
127127
args: ['push', '--all-tags', 'gcr.io/oss-vdb/record-checker']
128128
waitFor: ['build-record-checker', 'cloud-build-queue']
129129

130+
- name: 'gcr.io/cloud-builders/docker'
131+
entrypoint: 'bash'
132+
args: ['-c', 'docker pull gcr.io/oss-vdb/custommetrics:latest || exit 0']
133+
id: 'pull-custommetrics'
134+
waitFor: ['setup']
135+
- name: gcr.io/cloud-builders/docker
136+
args: ['build', '-t', 'gcr.io/oss-vdb/custommetrics:latest', '-t', 'gcr.io/oss-vdb/custommetrics:$COMMIT_SHA', '-f', 'cmd/custommetrics/Dockerfile', '--cache-from', 'gcr.io/oss-vdb/custommetrics:latest', '--pull', '.']
137+
dir: 'go'
138+
id: 'build-custommetrics'
139+
waitFor: ['pull-custommetrics']
140+
- name: gcr.io/cloud-builders/docker
141+
args: ['push', '--all-tags', 'gcr.io/oss-vdb/custommetrics']
142+
waitFor: ['build-custommetrics', 'cloud-build-queue']
143+
130144
# Build/push staging-api-test images to gcr.io/oss-vdb-test.
131145
- name: gcr.io/cloud-builders/docker
132146
args: ['build', '-t', 'gcr.io/oss-vdb-test/staging-api-test:latest', '-t', 'gcr.io/oss-vdb-test/staging-api-test:$COMMIT_SHA', '.']
@@ -337,7 +351,8 @@ steps:
337351
nvd-mirror=gcr.io/oss-vdb/nvd-mirror:$COMMIT_SHA,\
338352
recoverer=gcr.io/oss-vdb/recoverer:$COMMIT_SHA,\
339353
cve5-to-osv=gcr.io/oss-vdb/cve5-to-osv:$COMMIT_SHA,\
340-
record-checker=gcr.io/oss-vdb/record-checker:$COMMIT_SHA"
354+
record-checker=gcr.io/oss-vdb/record-checker:$COMMIT_SHA,\
355+
custommetrics=gcr.io/oss-vdb/custommetrics:$COMMIT_SHA"
341356
]
342357
dir: deployment/clouddeploy/gke-workers
343358

@@ -396,3 +411,4 @@ images:
396411
- 'gcr.io/oss-vdb/recoverer:$COMMIT_SHA'
397412
- 'gcr.io/oss-vdb/cve5-to-osv:$COMMIT_SHA'
398413
- 'gcr.io/oss-vdb/record-checker:$COMMIT_SHA'
414+
- 'gcr.io/oss-vdb/custommetrics:$COMMIT_SHA'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: custommetrics
5+
labels:
6+
cronLastSuccessfulTimeMins: "5"
7+
spec:
8+
schedule: "* * * * *"
9+
concurrencyPolicy: Forbid
10+
jobTemplate:
11+
spec:
12+
template:
13+
spec:
14+
containers:
15+
- name: custommetrics
16+
image: custommetrics
17+
imagePullPolicy: Always
18+
resources:
19+
requests:
20+
cpu: "1"
21+
memory: "256Mi"
22+
limits:
23+
cpu: "2"
24+
memory: "512Mi"
25+
restartPolicy: Never

deployment/clouddeploy/gke-workers/base/exporter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: CronJob
33
metadata:
44
name: exporter
55
labels:
6-
cronLastSuccessfulTimeMins: "180"
6+
cronLastSuccessfulTimeMins: "30"
77
spec:
88
schedule: "*/15 * * * *"
99
concurrencyPolicy: Forbid

deployment/clouddeploy/gke-workers/base/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ resources:
2727
- recoverer.yaml
2828
- record-checker.yaml
2929
- cve5-to-osv.yaml
30+
- custommetrics.yaml
31+

deployment/clouddeploy/gke-workers/base/recoverer.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ spec:
3030
- name: recoverer
3131
image: recoverer
3232
imagePullPolicy: Always
33+
resources:
34+
requests:
35+
cpu: "10m"
36+
memory: "256Mi"
37+
limits:
38+
cpu: "200m"
39+
memory: "512Mi"
40+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: custommetrics
5+
spec:
6+
jobTemplate:
7+
spec:
8+
template:
9+
spec:
10+
containers:
11+
- name: custommetrics
12+
env:
13+
- name: GOOGLE_CLOUD_PROJECT
14+
value: oss-vdb-test
15+

deployment/clouddeploy/gke-workers/environments/oss-vdb-test/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ patches:
2323
- path: generate-sitemap.yaml
2424
- path: recoverer.yaml
2525
- path: record-checker.yaml
26+
- path: custommetrics.yaml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: custommetrics
5+
spec:
6+
jobTemplate:
7+
spec:
8+
template:
9+
spec:
10+
containers:
11+
- name: custommetrics
12+
env:
13+
- name: GOOGLE_CLOUD_PROJECT
14+
value: oss-vdb
15+

deployment/clouddeploy/gke-workers/environments/oss-vdb/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ patches:
2222
- path: recoverer.yaml
2323
- path: record-checker.yaml
2424
- path: cve5-to-osv.yaml
25+
- path: custommetrics.yaml
26+

go/cmd/custommetrics/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang:1.25.3-alpine@sha256:aee43c3ccbf24fdffb7295693b6e33b21e01baec1b2a55acc351fde345e9ec34 AS build
16+
17+
WORKDIR /src
18+
19+
COPY ./go.mod /src/go.mod
20+
COPY ./go.sum /src/go.sum
21+
RUN go mod download && go mod verify
22+
23+
24+
COPY ./ /src/
25+
RUN CGO_ENABLED=0 go build -o custommetrics ./cmd/custommetrics
26+
27+
FROM gcr.io/distroless/static-debian12@sha256:87bce11be0af225e4ca761c40babb06d6d559f5767fbf7dc3c47f0f1a466b92c
28+
29+
COPY --from=build /src/custommetrics /
30+
31+
ENTRYPOINT ["/custommetrics"]

0 commit comments

Comments
 (0)