Skip to content

Commit 620c564

Browse files
committed
unittests
1 parent 1d046c2 commit 620c564

26 files changed

Lines changed: 516 additions & 442 deletions

README.md

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# keepup
22

3-
A lightweight Prometheus exporter that collects infrastructure inventory pushed by remote agents - OS releases, package versions (with end-of-life enrichment), and Kubernetes/Helm deployments - and exposes it as metrics.
3+
A lightweight Prometheus exporter that collects infrastructure inventory pushed by remote agents - package versions (with end-of-life enrichment) and Kubernetes/Helm deployments - and exposes it as metrics.
44

55
`keepup` holds no state of its own: Redis is both the write buffer and the read source. Agents `PUT` JSON, `keepup` validates and stores it with a TTL, and Prometheus scrapes `/metrics` on demand.
66

@@ -10,7 +10,6 @@ A lightweight Prometheus exporter that collects infrastructure inventory pushed
1010
- [Quick start](#quick-start)
1111
- [Configuration](#configuration)
1212
- [API](#api)
13-
- [`PUT /os-release`](#put-os-release)
1413
- [`PUT /package-version`](#put-package-version)
1514
- [`PUT /helm-cluster`](#put-helm-cluster)
1615
- [Metrics](#metrics)
@@ -22,18 +21,16 @@ A lightweight Prometheus exporter that collects infrastructure inventory pushed
2221

2322
```
2423
agent(s) keepup Prometheus
25-
┌─────────┐ PUT + token ┌───────────────────┐ scrape ┌────────────┐
26-
│ os-info │ ───────────────>│ handler ──▶ Redis │<────────│ /metrics │
27-
│ pkg-vers│ │ (TTL) │ │ │
28-
│ helm │ └───────────────────┘ └────────────┘
29-
└─────────┘
24+
----------- PUT + token --------------------- scrape --------------
25+
│ pkg-vers│ --------------->│ handler --> Redis │<---------│ /metrics |
26+
│ helm │ │ (TTL) │ │ │
27+
----------- --------------------- --------------
3028
```
3129

3230
Every data domain follows the same shape:
3331

3432
| Domain | Endpoint | Redis key | Metric |
3533
|---|---|---|---|
36-
| OS release *(deprecated)* | `PUT /os-release` | SHA1 of `{data_center}-{host_ip}` | `os_release_info` |
3734
| Package versions | `PUT /package-version` | SHA1 of `{data_center}-{host_ip}-PACKAGE_UUID` | `package_version_info` |
3835
| Kubernetes / Helm | `PUT /helm-cluster` | SHA1 of `{cluster_name}` | `kubernetes_cluster_info` |
3936

@@ -58,7 +55,7 @@ docker build -f docker/Dockerfile -t keepup .
5855

5956
The server listens on `LISTEN_PORT` (default `9101` in dev) and exposes:
6057

61-
- `PUT`/`GET /os-release`, `/package-version`, `/helm-cluster` - data ingestion & lookup (require `x-api-token`)
58+
- `PUT`/`GET /package-version`, `/helm-cluster` - data ingestion & lookup (require `x-api-token`)
6259
- `GET /metrics` - Prometheus scrape endpoint (no auth)
6360
- `GET /healthcheck` - liveness probe
6461

@@ -80,23 +77,6 @@ Config is loaded from environment variables. If `APP_ENV` is unset, `keepup` loa
8077

8178
All data endpoints require an `x-api-token` header matching `API_TOKEN`, and accept both `PUT` (insert) and `GET` (lookup by `id`).
8279

83-
### `PUT /os-release`
84-
85-
> **Deprecated** - kept for backwards compatibility, no longer receiving new fields (e.g. `team`). Do not build new integrations against it.
86-
87-
```jsonc
88-
{
89-
"release": {
90-
"os_id": "debian",
91-
"version_codename": "bullseye",
92-
"version": "11 (bullseye)",
93-
"version_id": "11",
94-
"data_center": "aaa",
95-
"host_ip": "101.122.418.4"
96-
}
97-
}
98-
```
99-
10080
### `PUT /package-version`
10181

10282
```jsonc
@@ -135,13 +115,18 @@ Unlike the other two endpoints, the request body maps directly onto the stored s
135115

136116
| Metric | Labels |
137117
|---|---|
138-
| `os_release_info` *(deprecated)* | `id`, `os_id`, `version_codename`, `version`, `version_id`, `data_center`, `host_ip` |
139118
| `package_version_info` | `id`, `package_name`, `current_version`, `current_version_eof`, `newest_version`, `expired`, `data_center`, `host_ip`, `team` |
140119
| `kubernetes_cluster_info` | `id`, `cluster_name`, `kube_version`, `chart_name`, `chart_version`, `chart_namespace`, `team` |
141120

142121
## Testing
143122

144-
There are no unit tests - only an end-to-end shell script that exercises all three endpoints against a running server:
123+
Unit tests cover the handler package against an in-process fake Redis ([`miniredis`](https://github.com/alicebob/miniredis)) - no external services required:
124+
125+
```bash
126+
go test ./...
127+
```
128+
129+
An end-to-end shell script also exercises both endpoints against a running server:
145130

146131
```bash
147132
# start the server first (see Quick start), then:

charts/keepup/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
apiVersion: v2
33
name: keepup
44
description: eondoflife.date version tracker service
5-
version: 1.7.0
6-
appVersion: 1.6.0
5+
version: 1.7.1
6+
appVersion: 1.7.0

charts/keepup/templates/_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
name: keepup-config
66
key: APP_ENV
77

8+
- name: LISTEN_PORT
9+
valueFrom:
10+
configMapKeyRef:
11+
name: keepup-config
12+
key: LISTEN_PORT
13+
814
- name: REDIS_ADDR
915
valueFrom:
1016
configMapKeyRef:

charts/keepup/templates/confiig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ kind: ConfigMap
22
apiVersion: v1
33
metadata:
44
name: keepup-config
5-
namespace: keepup
65
data:
76
APP_ENV: {{ .Values.appEnv | quote }}
7+
LISTEN_PORT: {{ .Values.listenPort | quote }}
88
REDIS_ADDR: {{ .Values.redisAddr | quote }}
99
REDIS_PORT: {{ .Values.redisPort | quote }}
1010
REDIS_DBNO: {{ .Values.redisDbNo | quote }}

charts/keepup/templates/deployment.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ spec:
2222
{{- toYaml .Values.annotations | nindent 8 }}
2323
{{- end }}
2424
spec:
25+
{{- with .Values.podSecurityContext }}
26+
securityContext: {{ toYaml . | nindent 8 }}
27+
{{- end }}
2528
{{- if .Values.nodeSelector }}
2629
nodeSelector:
2730
{{- toYaml .Values.nodeSelector | nindent 8 }}
@@ -35,15 +38,24 @@ spec:
3538
- name: keepup-redis-container
3639
imagePullPolicy: {{ .Values.redis.pullPolicy }}
3740
image: {{ .Values.redis.image | quote }}
41+
{{- with .Values.redis.securityContext }}
42+
securityContext: {{ toYaml . | nindent 12 }}
43+
{{- end }}
3844
{{ end }}
3945
- name: keepup-main-container
4046
imagePullPolicy: {{ .Values.main.pullPolicy }}
4147
image: "{{ .Values.main.image }}:{{ .Values.main.tag | default .Chart.AppVersion }}"
4248
env:
4349
{{ include "project.config" . | indent 12 }}
50+
{{- with .Values.main.securityContext }}
51+
securityContext: {{ toYaml . | nindent 12 }}
52+
{{- end }}
53+
ports:
54+
- name: http
55+
containerPort: {{ .Values.listenPort | int }}
4456
readinessProbe:
4557
httpGet:
4658
path: /healthcheck
47-
port: 80
59+
port: http
4860
initialDelaySeconds: 10
4961
periodSeconds: 60

charts/keepup/templates/httproute.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ spec:
1515
{{- end }}
1616
rules:
1717
- matches:
18-
- path:
19-
type: PathPrefix
20-
value: /os-release
2118
- path:
2219
type: PathPrefix
2320
value: /helm-cluster

charts/keepup/templates/ingress.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ spec:
1515
- host: {{ .Values.ingress.host }}
1616
http:
1717
paths:
18-
- path: /os-release
19-
pathType: ImplementationSpecific
20-
backend:
21-
service:
22-
name: keepup-service
23-
port:
24-
number: 80
2518
- path: /helm-cluster
2619
pathType: ImplementationSpecific
2720
backend:

charts/keepup/templates/seecret.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ kind: Secret
22
apiVersion: v1
33
metadata:
44
name: keepup-seecret
5-
namespace: keepup
65
data:
76
API_TOKEN: {{ .Values.apiToken | b64enc }}
87
type: Opaque

charts/keepup/templates/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ spec:
1414
- name: http
1515
protocol: TCP
1616
port: 80
17-
targetPort: 80
17+
targetPort: http

charts/keepup/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
replicas: 1
22

3+
podSecurityContext:
4+
seccompProfile:
5+
type: RuntimeDefault
6+
37
main:
48
image: "ghcr.io/code-tool/keepup"
59
tag: ""
610
pullPolicy: "IfNotPresent"
11+
securityContext:
12+
runAsNonRoot: true
13+
runAsUser: 1000
14+
allowPrivilegeEscalation: false
15+
readOnlyRootFilesystem: true
16+
capabilities:
17+
drop: ["ALL"]
718

819
redis:
920
enabled: true
1021
image: "redis:8.2.8"
1122
pullPolicy: "IfNotPresent"
23+
# the official redis image's built-in non-root user
24+
securityContext:
25+
runAsNonRoot: true
26+
runAsUser: 999
27+
allowPrivilegeEscalation: false
28+
capabilities:
29+
drop: ["ALL"]
1230

1331
ingress:
1432
enabled: true
@@ -50,6 +68,7 @@ tolerations: []
5068

5169
apiToken: ''
5270
appEnv: prod
71+
listenPort: '9101'
5372
redisAddr: 127.0.0.1
5473
redisPort: '6379'
5574
redisDbNo: '7'

0 commit comments

Comments
 (0)