Skip to content

Commit

Permalink
Improve monitoring config
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Sep 23, 2023
1 parent a1b112f commit 6316e21
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
8 changes: 4 additions & 4 deletions timoni/podinfo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ values: {

### Monitoring values

| Key | Type | Default | Description |
|-------------------------|----------|---------|-------------------------------------------------------------------------------|
| `monitoring: enabled:` | `bool` | `false` | Enable [Prometheus ServiceMonitor](https://prometheus-operator.dev/) creation |
| `monitoring: interval:` | `string` | `15s` | Prometheus scrape interval |
| Key | Type | Default | Description |
|-------------------------|--------|---------|-------------------------------------------------------------------------------|
| `monitoring: enabled:` | `bool` | `false` | Enable [Prometheus ServiceMonitor](https://prometheus-operator.dev/) creation |
| `monitoring: interval:` | `int` | `15` | Prometheus scrape interval in seconds |

### Cashing values

Expand Down
11 changes: 8 additions & 3 deletions timoni/podinfo/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
metadata: version: moduleVersion

// Deployment
replicas: *1 | int & >0
replicas: *1 | int & >=0

// Pod
podAnnotations?: {[ string]: string}
Expand All @@ -33,7 +33,11 @@ import (
securityContext?: corev1.#SecurityContext

// Service
service: port: *80 | int & >0 & <=65535
service: {
port: *80 | int & >0 & <=65535
annotations?: {[ string]: string}
labels?: {[ string]: string}
}

// HorizontalPodAutoscaler (optional)
autoscaling: {
Expand All @@ -50,13 +54,14 @@ import (
tls: *false | bool
host: *"podinfo.local" | string
annotations?: {[ string]: string}
labels?: {[ string]: string}
className?: string
}

// ServiceMonitor (optional)
monitoring: {
enabled: *false | bool
interval: *"15s" | string
interval: *15 | int & >=5 & <=3600
}

// Caching (optional)
Expand Down
17 changes: 17 additions & 0 deletions timoni/podinfo/templates/deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ import (
if !_config.autoscaling.enabled {
replicas: _config.replicas
}
strategy: {
type: "RollingUpdate"
rollingUpdate: maxUnavailable: "50%"
}
selector: matchLabels: _config.metadata.labelSelector
template: {
metadata: {
labels: _config.metadata.labelSelector
if _config.podAnnotations != _|_ {
annotations: _config.podAnnotations
}
if !_config.monitoring.enabled {
annotations: {
"prometheus.io/scrape": "true"
"prometheus.io/port": "9797"
}
}
}
spec: corev1.#PodSpec & {
serviceAccountName: _config.metadata.name
Expand All @@ -42,6 +52,11 @@ import (
containerPort: 9898
protocol: "TCP"
},
{
name: "http-metrics"
containerPort: 9797
protocol: "TCP"
},
]
livenessProbe: {
httpGet: {
Expand All @@ -64,6 +79,8 @@ import (
command: [
"./podinfo",
"--level=info",
"--port=9898",
"--port-metrics=9797",
if _config.caching.enabled {
"--cache-server=\(_config.caching.redisURL)"
},
Expand Down
3 changes: 3 additions & 0 deletions timoni/podinfo/templates/ingress.cue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
name: _config.metadata.name
namespace: _config.metadata.namespace
labels: _config.metadata.labels
if _config.ingress.labels != _|_ {
labels: _config.ingress.labels
}
if _config.metadata.annotations != _|_ {
annotations: _config.metadata.annotations
}
Expand Down
14 changes: 14 additions & 0 deletions timoni/podinfo/templates/service.cue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import (
name: _config.metadata.name
namespace: _config.metadata.namespace
labels: _config.metadata.labels
if _config.service.labels != _|_ {
labels: _config.service.labels
}
if _config.metadata.annotations != _|_ {
annotations: _config.metadata.annotations
}
if _config.service.annotations != _|_ {
annotations: _config.service.annotations
}
}
spec: corev1.#ServiceSpec & {
type: corev1.#ServiceTypeClusterIP
Expand All @@ -26,6 +32,14 @@ import (
targetPort: "\(name)"
protocol: "TCP"
},
if _config.monitoring.enabled {
{
name: "http-metrics"
port: 9797
targetPort: "http-metrics"
protocol: "TCP"
}
},
]
}
}
2 changes: 1 addition & 1 deletion timoni/podinfo/templates/servicemonitor.cue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
endpoints: [{
path: "/metrics"
port: "http-metrics"
interval: _config.monitoring.interval
interval: "\(_config.monitoring.interval)s"
}]
namespaceSelector: matchNames: [_config.metadata.namespace]
selector: matchLabels: _config.metadata.labelSelector
Expand Down

0 comments on commit 6316e21

Please sign in to comment.