From 81b573ad6da5f242cf9e0fb0484af7d3e58e4f46 Mon Sep 17 00:00:00 2001 From: janni06 Date: Fri, 9 Jan 2026 14:33:27 +0100 Subject: [PATCH 1/5] Expose version info and install time Loaded from configuration file and exposed in prometheus exporter --- main.go | 33 +++++++++++++++++++++++++++++++++ opencast-ca-display.yml | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/main.go b/main.go index 604a63f..a1fcc38 100644 --- a/main.go +++ b/main.go @@ -125,6 +125,11 @@ type Config struct { Prometheus bool Listen string } + + Version struct { + Version string + Installed int64 + } } var ( @@ -170,6 +175,20 @@ var ( }, []string{"state"}) ) +var ( + versionCollector = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "version_info", + Help: "Version information of the software", + }, []string{"version"}) + + installedCollector = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "installed_timestamp", + Help: "Timestamp when the software was installed", + }) +) + + + func loadConfig(configPath string) (*Config, error) { // Open config file yamlFile, err := os.ReadFile(configPath) @@ -201,6 +220,18 @@ func loadConfig(configPath string) (*Config, error) { config.Timeout = 500 } + if config.Version.Version == "" { + config.Version.Version = "unknown" + } + + // Set version metric + versionCollector.WithLabelValues(config.Version.Version).Set(1) + + // Set installed timestamp metric + if config.Version.Installed > 0 { + installedCollector.Set(float64(config.Version.Installed)) + } + return &config, nil } @@ -396,6 +427,8 @@ func setupRouter() *gin.Engine { func init() { prometheus.MustRegister(stateCollector) prometheus.MustRegister(timeCollector) + prometheus.MustRegister(versionCollector) + prometheus.MustRegister(installedCollector) } func setupMetricsRouter() *gin.Engine { diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index 62f1595..248c257 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -128,3 +128,9 @@ metrics: # Enable Prometheus metrics prometheus: true listen: 0.0.0.0:9100 + +version: + # Application version + version: 0.1.13 + # Installation timestamp (unix epoch). If left blank, it will be set on first run + installed: 1767962682 From 6fddb835a825b791a08a0ab494470f492c8f82c0 Mon Sep 17 00:00:00 2001 From: janni06 Date: Fri, 9 Jan 2026 15:31:39 +0100 Subject: [PATCH 2/5] Remove unnecessary blank lines in main.go --- main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.go b/main.go index a1fcc38..7374c4c 100644 --- a/main.go +++ b/main.go @@ -187,8 +187,6 @@ var ( }) ) - - func loadConfig(configPath string) (*Config, error) { // Open config file yamlFile, err := os.ReadFile(configPath) From f73f5bb655b0a0b394b5eeefeaf42f018e1c8653 Mon Sep 17 00:00:00 2001 From: janni06 Date: Fri, 9 Jan 2026 15:36:56 +0100 Subject: [PATCH 3/5] Remove false comment --- opencast-ca-display.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index 248c257..146a692 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -132,5 +132,5 @@ metrics: version: # Application version version: 0.1.13 - # Installation timestamp (unix epoch). If left blank, it will be set on first run + # Installation timestamp (unix epoch) installed: 1767962682 From e5dda38bf670283b46968f43753b1fe82de02639 Mon Sep 17 00:00:00 2001 From: janni06 Date: Fri, 9 Jan 2026 16:03:11 +0100 Subject: [PATCH 4/5] Expose major, minor, patch version info individually (versions specified at compile time) --- main.go | 63 ++++++++++++++++++++++++++++++++--------- opencast-ca-display.yml | 2 -- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 7374c4c..b49a01a 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,12 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) +const ( + majorVersion = 0 + minorVersion = 1 + patchVersion = 3 +) + type AgentStateResult struct { Update struct { Name string @@ -127,7 +133,6 @@ type Config struct { } Version struct { - Version string Installed int64 } } @@ -157,6 +162,16 @@ func (c *myCollector) Collect(ch chan<- prometheus.Metric) { ch <- s } +type constCollector struct { + desc *prometheus.Desc + value float64 +} + +func (c constCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.desc } +func (c constCollector) Collect(ch chan<- prometheus.Metric) { + ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, c.value) +} + var ( timeCollector = &myCollector{ metric: prometheus.NewDesc( @@ -176,11 +191,38 @@ var ( ) var ( - versionCollector = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "version_info", - Help: "Version information of the software", - }, []string{"version"}) + versionCollectorMajor = constCollector{ + desc: prometheus.NewDesc( + "version_info_major", + "Major Version number", + nil, + nil, + ), + value: float64(majorVersion), + } + versionCollectorMinor = constCollector{ + desc: prometheus.NewDesc( + "version_info_minor", + "Minor Version number", + nil, + nil, + ), + value: float64(minorVersion), + } + + versionCollectorPatch = constCollector{ + desc: prometheus.NewDesc( + "version_info_patch", + "Patch Version number", + nil, + nil, + ), + value: float64(patchVersion), + } +) + +var ( installedCollector = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "installed_timestamp", Help: "Timestamp when the software was installed", @@ -218,13 +260,6 @@ func loadConfig(configPath string) (*Config, error) { config.Timeout = 500 } - if config.Version.Version == "" { - config.Version.Version = "unknown" - } - - // Set version metric - versionCollector.WithLabelValues(config.Version.Version).Set(1) - // Set installed timestamp metric if config.Version.Installed > 0 { installedCollector.Set(float64(config.Version.Installed)) @@ -425,7 +460,9 @@ func setupRouter() *gin.Engine { func init() { prometheus.MustRegister(stateCollector) prometheus.MustRegister(timeCollector) - prometheus.MustRegister(versionCollector) + prometheus.MustRegister(versionCollectorMajor) + prometheus.MustRegister(versionCollectorMinor) + prometheus.MustRegister(versionCollectorPatch) prometheus.MustRegister(installedCollector) } diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index 146a692..542826c 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -130,7 +130,5 @@ metrics: listen: 0.0.0.0:9100 version: - # Application version - version: 0.1.13 # Installation timestamp (unix epoch) installed: 1767962682 From 5dc89aa25cc548ceccbfbcca1eb483ed0e387d7c Mon Sep 17 00:00:00 2001 From: janni06 Date: Fri, 9 Jan 2026 16:30:03 +0100 Subject: [PATCH 5/5] Document creating a new release --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 417df8b..eaf05ec 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,11 @@ Next, go to the Opencast REST Docs → `/user-utils` and fill out the form for - roles: `["ROLE_CAPTURE_AGENT_CALENDAR"]` You should now be able to use this new user. + +## Creating a Release + +Creating a new release now involves multiple steps: + +1. Decide type of release => releases are named in the following form `v(majorVersion).(minorVersion).(patchVersion)`. +2. Set the new release number in the `main.go` file (variables named accordingly in lines 41-43). +3. Create the new release. \ No newline at end of file