|
| 1 | +package configuration |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/prometheus/client_golang/prometheus" |
| 7 | +) |
| 8 | + |
| 9 | +var ( |
| 10 | + // Commit current build commit set by build script. |
| 11 | + Commit = "0" |
| 12 | + // BuildTime set by build script in ISO 8601 (UTC) format: |
| 13 | + // YYYY-MM-DDThh:mm:ssTZD (see https://www.w3.org/TR/NOTE-datetime for |
| 14 | + // details). |
| 15 | + BuildTime = "0" |
| 16 | + // StartTime in ISO 8601 (UTC) format. |
| 17 | + StartTime = time.Now().UTC().Format("2006-01-02T15:04:05Z") |
| 18 | +) |
| 19 | + |
| 20 | +var ( |
| 21 | + // RegistrationServiceShortCommitGaugeVec reflects the current short git commit of the registration service (via the `commit` label) |
| 22 | + RegistrationServiceShortCommitGaugeVec *prometheus.GaugeVec |
| 23 | + // RegistrationServiceCommitGaugeVec reflects the current full git commit of the registration service (via the `commit` label) |
| 24 | + RegistrationServiceCommitGaugeVec *prometheus.GaugeVec |
| 25 | +) |
| 26 | + |
| 27 | +func RegisterVersionMetrics(registry *prometheus.Registry) { |
| 28 | + // RegistrationServiceCommitGaugeVec reflects the current full git commit of the registration service (via the `commit` label) |
| 29 | + RegistrationServiceCommitGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 30 | + Name: "sandbox_registration_service_commit", |
| 31 | + Help: "The commit of the registration service", |
| 32 | + }, []string{"commit"}) |
| 33 | + RegistrationServiceCommitGaugeVec.WithLabelValues(Commit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit |
| 34 | + |
| 35 | + // RegistrationServiceShortCommitGaugeVec reflects the current short git commit of the registration service (via the `commit` label) |
| 36 | + RegistrationServiceShortCommitGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 37 | + Name: "sandbox_registration_service_short_commit", |
| 38 | + Help: "The short commit of the registration service", |
| 39 | + }, []string{"commit"}) |
| 40 | + shortCommit := Commit |
| 41 | + if len(Commit) >= 7 { |
| 42 | + shortCommit = Commit[0:7] |
| 43 | + } |
| 44 | + RegistrationServiceShortCommitGaugeVec.WithLabelValues(shortCommit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit |
| 45 | + registry.MustRegister(RegistrationServiceCommitGaugeVec, RegistrationServiceShortCommitGaugeVec) |
| 46 | +} |
0 commit comments