Skip to content

Commit 4554bcf

Browse files
authored
Merge pull request #385 from orange-cloudfoundry/master
Update credhub exporter
2 parents 20cf1d8 + 8cf4445 commit 4554bcf

File tree

15 files changed

+125
-143
lines changed

15 files changed

+125
-143
lines changed

jobs/credhub_alerts/templates/credhub.alerts.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ groups:
22
- name: credhub
33
rules:
44
- alert: CredhubCrendentialAging
5-
expr: max(round((time() - max_over_time(credhub_credential_created_at{}[1h])) / 86400)) by (deployment, environment, path) > <%= p('credhub_alerts.credential_expire.threshold') %>
5+
expr: (time() - credhub_credential_created_at) / 86400 > <%= p('credhub_alerts.credential_expire.threshold') %>
66
for: <%= p('credhub_alerts.credential_expire.evaluation_time') %>
77
labels:
88
severity: warning
@@ -11,7 +11,7 @@ groups:
1111
description: "Credhub credential `{{$labels.path}}` at environment `{{$labels.environment}}`, deployment `{{$labels.deployment}}` has not been rotated in the last <%= p('credhub_alerts.credential_expire.threshold') %> days"
1212

1313
- alert: CredhubCertificateWillExpire
14-
expr: min(round((max_over_time(credhub_certificate_expires_at{}[1h]) - time()) / 86400)) by (deployment, environment, path) < <%= p('credhub_alerts.certificate_expire.threshold') %>
14+
expr: (credhub_certificate_expires_at - time()) / 86400 < <%= p('credhub_alerts.certificate_expire.threshold') %>
1515
for: <%= p('credhub_alerts.certificate_expire.evaluation_time') %>
1616
labels:
1717
severity: critical

jobs/credhub_alerts/templates/prometheus_credhub_exporter.alerts.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ groups:
22
- name: prometheus-credhub-exporter
33
rules:
44
- alert: CredhubExporterApplicationsScrapeError
5-
expr: max(max_over_time(credhub_last_scrape_error{}[1h])) by(director, environment) != 0
5+
expr: credhub_last_scrape_error != 0
66
for: <%= p('credhub_alerts.scrape_error.evaluation_time') %>
77
labels:
88
service: credhub-exporter
@@ -12,7 +12,7 @@ groups:
1212
description: "The `credhub_exporter` at `{{$labels.environment}}/{{$labels.director}}` was unable to scrape metrics during the last <%= p('credhub_alerts.scrape_error.evaluation_time') %>"
1313

1414
- alert: CredhubExporterScrapeTooOld
15-
expr: (time() - max(max_over_time(credhub_last_scrape_timestamp{}[1h])) by(environment, deployment)) > <%= p('credhub_alerts.scrape_too_old.threshold') %>
15+
expr: time() - credhub_last_scrape_timestamp > <%= p('credhub_alerts.scrape_too_old.threshold') %>
1616
for: <%= p('credhub_alerts.scrape_too_old.evaluation_time') %>
1717
labels:
1818
service: credhub-exporter

jobs/credhub_dashboards/templates/credhub_certs.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"editable": false,
4747
"gnetId": null,
4848
"graphTooltip": 0,
49-
"id": null,
50-
"iteration": 1573825587650,
49+
"id": 105,
50+
"iteration": 1586246148529,
5151
"links": [
5252
{
5353
"asDropdown": true,
@@ -88,7 +88,7 @@
8888
"pageSize": 150,
8989
"showHeader": true,
9090
"sort": {
91-
"col": 3,
91+
"col": 7,
9292
"desc": false
9393
},
9494
"styles": [
@@ -165,20 +165,20 @@
165165
"60"
166166
],
167167
"type": "number",
168-
"unit": "d"
168+
"unit": "s"
169169
}
170170
],
171171
"targets": [
172172
{
173-
"expr": "min(round(max_over_time(credhub_certificate_expires_at{environment=~\"$environment\",deployment=~\"$bosh_deployment\"}[1h]))) by (name, path) * 1000",
173+
"expr": "max by (environment, deployment, index, name, path) (\n credhub_certificate_expires_at{environment=~\"$environment\",deployment=~\"$bosh_deployment\"} * 1000\n)",
174174
"format": "table",
175175
"instant": true,
176176
"intervalFactor": 1,
177177
"legendFormat": "",
178178
"refId": "A"
179179
},
180180
{
181-
"expr": "min(round((max_over_time(credhub_certificate_expires_at{environment=~\"$environment\",deployment=~\"$bosh_deployment\"}[1h]) - time()) / 86400)) by (name, path)",
181+
"expr": "max by (environment, deployment, index, name, path) (\n credhub_certificate_expires_at{environment=~\"$environment\",deployment=~\"$bosh_deployment\"} - time()\n)",
182182
"format": "table",
183183
"instant": true,
184184
"intervalFactor": 1,
@@ -193,7 +193,7 @@
193193
"type": "table"
194194
}
195195
],
196-
"schemaVersion": 20,
196+
"schemaVersion": 21,
197197
"style": "dark",
198198
"tags": [
199199
"bosh"
@@ -267,5 +267,5 @@
267267
"timezone": "browser",
268268
"title": "CredHub: Certificate Expiry Date",
269269
"uid": "OQqSNUJZk",
270-
"version": 9
270+
"version": 10
271271
}

jobs/credhub_exporter/monit

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
check process credhub_exporter
2-
with pidfile /var/vcap/sys/run/credhub_exporter/credhub_exporter.pid
3-
start program "/var/vcap/jobs/credhub_exporter/bin/credhub_exporter_ctl start"
4-
stop program "/var/vcap/jobs/credhub_exporter/bin/credhub_exporter_ctl stop"
2+
with pidfile /var/vcap/sys/run/bpm/credhub_exporter/credhub_exporter.pid
3+
start program "/var/vcap/jobs/bpm/bin/bpm start credhub_exporter"
4+
stop program "/var/vcap/jobs/bpm/bin/bpm stop credhub_exporter"
55
group vcap

jobs/credhub_exporter/spec

+14-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ packages:
55
- credhub_exporter
66

77
templates:
8-
bin/credhub_exporter_ctl: bin/credhub_exporter_ctl
9-
config/web_tls_cert.pem: config/web_tls_cert.pem
10-
config/web_tls_key.pem: config/web_tls_key.pem
11-
config/credhub_tls_ca_cert.pem: config/credhub_tls_ca_cert.pem
8+
web_tls_cert.pem.erb: config/web_tls_cert.pem
9+
web_tls_key.pem.erb: config/web_tls_key.pem
10+
credhub_tls_ca_cert.pem.erb: config/credhub_tls_ca_cert.pem
11+
bpm.yml.erb: config/bpm.yml
1212

1313
consumes:
1414
- name: credhub
@@ -24,22 +24,30 @@ properties:
2424
description: "Credhub Client Secret"
2525
credhub_exporter.credhub.ca_certs:
2626
description: "Credhub CA certificates (PEM format)"
27+
default: ""
2728
credhub_exporter.metrics.deployment:
2829
description: "Deployment name to be reported as a metric label"
2930
credhub_exporter.metrics.environment:
3031
description: "Environment label to be attached to metrics"
3132
credhub_exporter.metrics.namespace:
3233
description: "Metrics Namespace"
34+
default: "credhub"
35+
credhub_exporter.metrics.update_interval:
36+
description: "Metrics update interval given as golang duration format"
37+
default: 6h
3338
credhub_exporter.filters.generic-certificates:
34-
description: "Json list of <regexp> to match generic credentials paths that may contains certificates"
39+
description: "List of <regexp> to match generic credentials paths that may contains certificates"
40+
default: []
3541
credhub_exporter.filters.name-like:
3642
description: "Fetch credentials whose name contains the query string (fetch all credentials when empty)"
3743
credhub_exporter.filters.path:
3844
description: "Fetch credentials that exist under the provided path"
3945
credhub_exporter.log_format:
4046
description: "Set the log target and format. Example: 'logger:syslog?appname=bob&local=7' or 'logger:stdout?json=true'"
47+
default: logger:stderr
4148
credhub_exporter.log_level:
4249
description: "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]"
50+
default: info
4351
credhub_exporter.skip_ssl_verify:
4452
description: "Disable SSL Verify"
4553
default: false
@@ -48,6 +56,7 @@ properties:
4856
default: "9358"
4957
credhub_exporter.web.telemetry_path:
5058
description: "Path under which to expose Prometheus metrics"
59+
default: "/metrics"
5160
credhub_exporter.web.auth_username:
5261
description: "Username for web interface basic auth"
5362
credhub_exporter.web.auth_password:

jobs/credhub_exporter/templates/bin/credhub_exporter_ctl

-108
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<%
2+
3+
credhub_url = nil
4+
credhub_ca_certs = nil
5+
if_link("credhub") do |link|
6+
credhub_url = sprintf("https://%s:%d", link.p("credhub.internal_url"), link.p("credhub.port"))
7+
credhub_ca_certs = link.p("credhub.ca_certificate")
8+
end
9+
unless credhub_url
10+
credhub_url = p("credhub_exporter.credhub.api_url")
11+
credhub_ca_certs = p("credhub_exporter.credhub.ca_certs")
12+
end
13+
14+
args = [
15+
"--log.level", p("credhub_exporter.log_level"),
16+
"--log.format", p("credhub_exporter.log_format"),
17+
]
18+
19+
env = {}
20+
env["CREDHUB_EXPORTER_API_URL"] = credhub_url
21+
env["CREDHUB_EXPORTER_CLIENT_ID"] = p("credhub_exporter.credhub.client_id")
22+
env["CREDHUB_EXPORTER_CLIENT_SECRET"] = p("credhub_exporter.credhub.client_secret")
23+
env["CREDHUB_EXPORTER_FILTER_NAMELIKE"] = p("credhub_exporter.filters.name-like", "")
24+
env["CREDHUB_EXPORTER_FILTER_PATH"] = p("credhub_exporter.filters.path", "")
25+
env["CREDHUB_EXPORTER_GENERIC_CERTIFICATES"] = p("credhub_exporter.filters.generic-certificates").to_json
26+
env["CREDHUB_EXPORTER_METRICS_DEPLOYMENT"] = p("credhub_exporter.metrics.deployment")
27+
env["CREDHUB_EXPORTER_METRICS_NAMESPACE"] = p("credhub_exporter.metrics.namespace")
28+
env["CREDHUB_EXPORTER_METRICS_ENVIRONMENT"] = p("credhub_exporter.metrics.environment")
29+
env["CREDHUB_EXPORTER_METRICS_UPDATE_INTERVAL"] = p("credhub_exporter.metrics.update_interval")
30+
env["CREDHUB_EXPORTER_WEB_LISTEN_ADDRESS"] = ":#{p("credhub_exporter.web.port")}"
31+
env["CREDHUB_EXPORTER_WEB_TELEMETRY_PATH"] = p("credhub_exporter.web.telemetry_path")
32+
env["CREDHUB_EXPORTER_WEB_AUTH_USERNAME"] = p("credhub_exporter.web.auth_username", "")
33+
env["CREDHUB_EXPORTER_WEB_AUTH_PASSWORD"] = p("credhub_exporter.web.auth_password", "")
34+
env["CREDHUB_EXPORTER_SKIP_SSL_VERIFY"] = "false"
35+
36+
if not credhub_ca_certs.empty?
37+
env["CREDHUB_EXPORTER_CA_CERTS_PATH"] = "/var/vcap/jobs/credhub_exporter/config/credhub_tls_ca_cert.pem"
38+
end
39+
40+
# when property value is true
41+
# -> not "if property exists"
42+
# -> always defined since it has a default value in spec
43+
if p("credhub_exporter.skip_ssl_verify")
44+
env["CREDHUB_EXPORTER_SKIP_SSL_VERIFY"] = "true"
45+
end
46+
47+
if_p("credhub_exporter.web.tls_cert", "credhub_exporter.web.tls_key") do
48+
env["CREDHUB_EXPORTER_WEB_TLS_CERTFILE"] = "/var/vcap/jobs/credhub_exporter/config/web_tls_cert.pem"
49+
env["CREDHUB_EXPORTER_WEB_TLS_KEYFILE"] = "/var/vcap/jobs/credhub_exporter/config/web_tls_key.pem"
50+
end
51+
52+
53+
[ "http", "https", "no" ].each do |key|
54+
name = "#{key}_proxy"
55+
if_p("env.#{name}") do |val|
56+
env[name.upcase] = val
57+
env[name] = val
58+
end
59+
end
60+
61+
config = {
62+
"processes" => [
63+
{
64+
"name" => "credhub_exporter",
65+
"executable" => "/var/vcap/packages/credhub_exporter/bin/credhub_exporter",
66+
"env" => env,
67+
"args" => args,
68+
}
69+
]
70+
}
71+
%>
72+
73+
<%= YAML.dump(config) %>

jobs/credhub_exporter/templates/config/credhub_tls_ca_cert.pem

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<% if_link("credhub") do |link| %>
2+
<%= link.p("credhub.ca_certificate") %>
3+
<% end.else do %>
4+
<%= p("credhub_exporter.credhub.ca_certs") %>
5+
<% end %>

manifests/operators/monitor-bosh.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
path: /instance_groups/name=prometheus2/jobs/name=prometheus2/properties/prometheus/scrape_configs/-
145145
value:
146146
job_name: credhub
147-
scrape_interval: 30m
148-
scrape_timeout: 4m
147+
scrape_interval: 4m
148+
scrape_timeout: 2m
149149
file_sd_configs:
150150
- files:
151151
- "/var/vcap/store/bosh_exporter/bosh_target_groups.json"

manifests/operators/use-bpm.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# add bpm to prometheus2
2+
- type: replace
3+
path: /instance_groups/name=prometheus2/jobs/-
4+
value:
5+
name: bpm
6+
release: bpm
7+
8+
- type: replace
9+
path: /releases/-
10+
value:
11+
name: bpm
12+
version: 1.1.8
13+
url: https://bosh.io/d/github.com/cloudfoundry/bpm-release?v=1.1.8
14+
sha1: c956394fce7e74f741e4ae8c256b480904ad5942

packages/credhub_exporter/packaging

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
set -eux
44

5-
# Copy common utils
6-
mkdir -p ${BOSH_INSTALL_TARGET}/common
7-
cp -a ${BOSH_COMPILE_TARGET}/common/* ${BOSH_INSTALL_TARGET}/common
8-
95
# Extract credhub_exporter package
106
mkdir -p ${BOSH_INSTALL_TARGET}/bin
11-
tar xzvf ${BOSH_COMPILE_TARGET}/credhub_exporter/credhub_exporter-0.1.6.linux-amd64.tar.gz
12-
cp -a ${BOSH_COMPILE_TARGET}/credhub_exporter-0.1.6.linux-amd64/* ${BOSH_INSTALL_TARGET}/bin
7+
unzip credhub_exporter/credhub_exporter-0.2.0-linux_amd64-0.2-0.zip credhub_exporter -d ${BOSH_INSTALL_TARGET}/bin

0 commit comments

Comments
 (0)