Skip to content

Commit

Permalink
Merge pull request #88 from appuio/feat/monitoring
Browse files Browse the repository at this point in the history
Add option to scrape APPUiO Cloud Agent metrics
  • Loading branch information
glrf authored Apr 7, 2022
2 parents ffa4927 + bb144dc commit 602e4bd
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 4 deletions.
1 change: 1 addition & 0 deletions class/appuio-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parameters:
- appuio-cloud/component/namespace-quota.jsonnet
- appuio-cloud/component/build-strategy.jsonnet
- appuio-cloud/component/runonce-activedeadlineseconds.jsonnet
- appuio-cloud/component/monitoring.jsonnet
input_type: jsonnet
output_path: appuio-cloud/
- input_paths:
Expand Down
5 changes: 4 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ parameters:
=_metadata: {}
namespace: appuio-cloud

monitoring:
enabled: true

images:
agent:
registry: ghcr.io
repository: appuio/appuio-cloud-agent
tag: v0.2.0
tag: v0.2.1

agent:
replicas: 3
Expand Down
11 changes: 11 additions & 0 deletions component/agent.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ local admissionWebhookService = loadManifest('webhook/service.yaml') {
},
};

local metricsService = loadManifest('manager/service.yaml') {
metadata+: {
namespace: params.namespace,
labels+: {
'control-plane': 'appuio-cloud-agent',
service: 'metrics',
},
},
};

{
'01_role': role,
'01_leader_election_role': leaderElectionRole,
Expand Down Expand Up @@ -140,4 +150,5 @@ local admissionWebhookService = loadManifest('webhook/service.yaml') {
'02_deployment': deployment,
'10_webhook_config': admissionWebhook,
'11_webhook_service': admissionWebhookService,
'20_metrics_service': metricsService,
}
19 changes: 17 additions & 2 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ local inv = kap.inventory();
// The hiera parameters for the component
local params = inv.parameters.appuio_cloud;

// Define outputs below
local isOpenshift = std.startsWith(inv.parameters.facts.distribution, 'openshift');
local monitoringLabel =
if isOpenshift then
{
'openshift.io/cluster-monitoring': 'true',
}
else
{
SYNMonitoring: 'main',
};


{
'00_namespace': kube.Namespace(params.namespace) + common.DefaultLabels,
'00_namespace': kube.Namespace(params.namespace) {
metadata+: {
labels+: monitoringLabel,
},
} + common.DefaultLabels,
}
36 changes: 36 additions & 0 deletions component/monitoring.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local prom = import 'lib/prom.libsonnet';
local inv = kap.inventory();
local params = inv.parameters.appuio_cloud;


local sm =
prom.ServiceMonitor('appuio-cloud-agent') {
metadata+: {
namespace: params.namespace,
labels+: {
'control-plane': 'appuio-cloud-agent',
service: 'metrics',
},
},
spec: {
endpoints: [ {
port: 'metrics-port',
} ],
namespaceSelector: { matchNames: [ params.namespace ] },
selector: {
matchLabels: {
'control-plane': 'appuio-cloud-agent',
service: 'metrics',
},
},
},
};

if params.monitoring.enabled then
{
'10_monitoring/00_servicemonitor-appuio-cloud-agent': sm,
}
else
{}
8 changes: 8 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ This parameter allows selecting the Docker images to us.
Each image is specified using keys `registry`, `repository` and `tag`.
This structure allows easily injecting a registry mirror, if required.

== `monitoring.enabled`

[horizontal]
type:: boolean
default:: `true`

Controls if `ServiceMonitor` object is created to scrape the APPUiO Cloud Agent metrics.

== `agent.replicas`

[horizontal]
Expand Down
5 changes: 5 additions & 0 deletions tests/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ parameters:
- type: https
source: https://raw.githubusercontent.com/projectsyn/component-resource-locker/v2.0.1/lib/resource-locker.libjsonnet
output_path: vendor/lib/resource-locker.libjsonnet
- type: https
source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/v1.13.0/lib/openshift4-monitoring-prom.libsonnet
output_path: vendor/lib/prom.libsonnet

appuio_cloud:
metrics:
enabled: true
agent:
webhook:
tls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: Namespace
metadata:
annotations: {}
labels:
SYNMonitoring: main
app.kubernetes.io/component: appuio-cloud
app.kubernetes.io/managed-by: commodore
app.kubernetes.io/name: appuio-cloud
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- --memory-per-core-limit=4Gi
command:
- appuio-cloud-agent
image: ghcr.io/appuio/appuio-cloud-agent:v0.2.0
image: ghcr.io/appuio/appuio-cloud-agent:v0.2.1
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -34,6 +34,7 @@ spec:
name: agent
ports:
- containerPort: 9443
- containerPort: 8080
readinessProbe:
httpGet:
path: /readyz
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
labels:
control-plane: appuio-cloud-agent
service: metrics
name: metrics-service
namespace: appuio-cloud
spec:
ports:
- name: metrics-port
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: appuio-cloud-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations: {}
labels:
control-plane: appuio-cloud-agent
name: appuio-cloud-agent
service: metrics
name: appuio-cloud-agent
namespace: appuio-cloud
spec:
endpoints:
- port: metrics-port
namespaceSelector:
matchNames:
- appuio-cloud
selector:
matchLabels:
control-plane: appuio-cloud-agent
service: metrics

0 comments on commit 602e4bd

Please sign in to comment.