Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
feat: add last_state metric (#357)
Browse files Browse the repository at this point in the history
It is a bit difficult to alert on sync_calls since they trigger into an error state and may stay there.
This adds the gauge last_state.  With last_state, people can easily alert on a value < 0 to indicate failure.
  • Loading branch information
cep21 authored Apr 23, 2020
1 parent b345ffd commit 1d9d237
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ kubernetes-external-secrets exposes the following metrics over a prometheus endp
| Metric | Description | Example |
| ----------------------------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `sync_calls` | This metric counts the number of sync calls by backend, secret name and status | `sync_calls{name="foo",namespace="example",backend="foo",status="success"} 1` |
| `last_state` | A value of -1 or 1 where -1 means the last sync_call was an error and 1 means the last sync_call was a success | `last_state{name="foo",namespace="example",backend="foo"} 1` |


## Development
Expand Down
2 changes: 2 additions & 0 deletions lib/metrics-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ describe('MetricsServer', () => {

expect(res.text).to.have.string('sync_calls{name="foo",namespace="example",backend="foo",status="success"} 1')
expect(res.text).to.have.string('sync_calls{name="bar",namespace="example",backend="foo",status="failed"} 1')
expect(res.text).to.have.string('last_state{name="foo",namespace="example",backend="foo"} 1')
expect(res.text).to.have.string('last_state{name="bar",namespace="example",backend="foo"} -1')
})
})
19 changes: 19 additions & 0 deletions lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Metrics {
labelNames: ['name', 'namespace', 'backend', 'status'],
registers: [registry]
})
this._lastState = new Prometheus.Gauge({
name: 'last_state',
help: 'Value -1 if the last sync was a failure, 1 otherwise.',
labelNames: ['name', 'namespace', 'backend'],
registers: [registry]
})
}

/**
Expand All @@ -31,6 +37,19 @@ class Metrics {
backend,
status
})
if (status === 'success') {
this._lastState.set({
name,
namespace,
backend
}, 1)
} else {
this._lastState.set({
name,
namespace,
backend
}, -1)
}
}
}

Expand Down

0 comments on commit 1d9d237

Please sign in to comment.