From d688e4a226ec019588a6d7fabd8ddeaa36e35f94 Mon Sep 17 00:00:00 2001 From: hainenber Date: Wed, 28 Feb 2024 22:10:13 +0700 Subject: [PATCH 1/3] chore: replace deprecated `io/ioutil` functions with modern equivalences Signed-off-by: hainenber --- config/config.go | 3 +-- exporter/http.go | 4 ++-- test/github_exporter_test.go | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index 278c5b0d..db130e3e 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,6 @@ package config import ( - "io/ioutil" "net/url" "path" "strings" @@ -118,7 +117,7 @@ func (c *Config) SetAPIToken(token string) { // SetAPITokenFromFile accepts a file containing an oauth2 token for usage in http.request func (c *Config) SetAPITokenFromFile(tokenFile string) error { - b, err := ioutil.ReadFile(tokenFile) + b, err := os.ReadFile(tokenFile) if err != nil { return err } diff --git a/exporter/http.go b/exporter/http.go index 037a47fc..273f63f4 100644 --- a/exporter/http.go +++ b/exporter/http.go @@ -2,7 +2,7 @@ package exporter import ( "fmt" - "io/ioutil" + "io" "net/http" neturl "net/url" "strconv" @@ -111,7 +111,7 @@ func getResponse(url string, token string, ch chan<- *Response) error { defer resp.Body.Close() // Read the body to a byte array so it can be used elsewhere - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("Error converting body to byte array: %v", err) } diff --git a/test/github_exporter_test.go b/test/github_exporter_test.go index ae454e9c..e5699de6 100644 --- a/test/github_exporter_test.go +++ b/test/github_exporter_test.go @@ -2,7 +2,7 @@ package test import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -145,7 +145,7 @@ func githubPullsError() *apitest.Mock { } func readFile(path string) string { - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { panic(err) } @@ -154,7 +154,7 @@ func readFile(path string) string { func bodyContains(substr string) func(*http.Response, *http.Request) error { return func(res *http.Response, req *http.Request) error { - bytes, err := ioutil.ReadAll(res.Body) + bytes, err := io.ReadAll(res.Body) if err != nil { panic(err) } From f1b6d8e26f533ce95501659f3023eca3359391d9 Mon Sep 17 00:00:00 2001 From: hainenber Date: Wed, 28 Feb 2024 23:08:40 +0700 Subject: [PATCH 2/3] feat(exporter): include Git tag as attribute for `github_repo_release_downloads` metrics Signed-off-by: hainenber --- exporter/metrics.go | 4 ++-- exporter/structs.go | 1 + test/github_exporter_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/exporter/metrics.go b/exporter/metrics.go index 679b2a0b..32618825 100644 --- a/exporter/metrics.go +++ b/exporter/metrics.go @@ -44,7 +44,7 @@ func AddMetrics() map[string]*prometheus.Desc { APIMetrics["ReleaseDownloads"] = prometheus.NewDesc( prometheus.BuildFQName("github", "repo", "release_downloads"), "Download count for a given release", - []string{"repo", "user", "release", "name", "created_at"}, nil, + []string{"repo", "user", "release", "name", "tag", "created_at"}, nil, ) APIMetrics["Limit"] = prometheus.NewDesc( prometheus.BuildFQName("github", "rate", "limit"), @@ -77,7 +77,7 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr for _, release := range x.Releases { for _, asset := range release.Assets { - ch <- prometheus.MustNewConstMetric(e.APIMetrics["ReleaseDownloads"], prometheus.GaugeValue, float64(asset.Downloads), x.Name, x.Owner.Login, release.Name, asset.Name, asset.CreatedAt) + ch <- prometheus.MustNewConstMetric(e.APIMetrics["ReleaseDownloads"], prometheus.GaugeValue, float64(asset.Downloads), x.Name, x.Owner.Login, release.Name, asset.Name, release.Tag, asset.CreatedAt) } } prCount := 0 diff --git a/exporter/structs.go b/exporter/structs.go index 283037d6..858b876f 100644 --- a/exporter/structs.go +++ b/exporter/structs.go @@ -44,6 +44,7 @@ type Datum struct { type Release struct { Name string `json:"name"` Assets []Asset `json:"assets"` + Tag string `json:"tag_name"` } type Pull struct { diff --git a/test/github_exporter_test.go b/test/github_exporter_test.go index ae454e9c..35421868 100644 --- a/test/github_exporter_test.go +++ b/test/github_exporter_test.go @@ -47,10 +47,10 @@ func TestGithubExporter(t *testing.T) { Assert(bodyContains(`github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 946`)). Assert(bodyContains(`github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 120`)). Assert(bodyContains(`github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 5`)). - Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_checksums.txt",release="1.3.0",repo="myRepo",user="myOrg"} 7292`)). - Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_windows_amd64.tar.gz",release="1.3.0",repo="myRepo",user="myOrg"} 21`)). - Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_checksums.txt",release="2.0.0",repo="myRepo",user="myOrg"} 14564`)). - Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_windows_amd64.tar.gz",release="2.0.0",repo="myRepo",user="myOrg"} 55`)). + Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_checksums.txt",release="1.3.0",repo="myRepo",tag="1.3.0",user="myOrg"} 7292`)). + Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_windows_amd64.tar.gz",release="1.3.0",repo="myRepo",tag="1.3.0",user="myOrg"} 21`)). + Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_checksums.txt",release="2.0.0",repo="myRepo",tag="2.0.0",user="myOrg"} 14564`)). + Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_windows_amd64.tar.gz",release="2.0.0",repo="myRepo",tag="2.0.0",user="myOrg"} 55`)). Status(http.StatusOK). End() } From 66a78934cebf03f00716bb59fd19ccf41a455deb Mon Sep 17 00:00:00 2001 From: Henry McConville Date: Tue, 5 Mar 2024 12:29:35 +0000 Subject: [PATCH 3/3] Version 1.1.0 release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index af0b7ddb..9084fa2f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.6 +1.1.0