Skip to content

Commit f3680ee

Browse files
authored
Merge branch 'master' into master
2 parents 3205a19 + 400a939 commit f3680ee

File tree

17 files changed

+99
-55
lines changed

17 files changed

+99
-55
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Setup Go
16-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v5
1717
with:
18-
go-version: '1.19.5'
18+
go-version: '1.22.1'
1919

2020
- name: Install dependencies
2121
run: go get .

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
*.pem
33
.idea/
44
.vscode/
5+
6+
# Build artifact
7+
./main

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
FROM golang:1.19.5-buster as build
2-
LABEL maintainer="Infinity Works"
1+
FROM golang:1.22-bookworm as build
2+
LABEL maintainer="githubexporter"
33

44
ENV GO111MODULE=on
55

6-
COPY ./ /go/src/github.com/infinityworks/github-exporter
7-
WORKDIR /go/src/github.com/infinityworks/github-exporter
6+
COPY ./ /go/src/github.com/githubexporter/github-exporter
7+
WORKDIR /go/src/github.com/githubexporter/github-exporter
88

99
RUN go mod download \
1010
&& go test ./... \
1111
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/main
1212

13-
FROM alpine:3.17.1
13+
FROM alpine:3
1414

1515
RUN apk --no-cache add ca-certificates \
1616
&& addgroup exporter \

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ test:
77
@go test -v -race ./...
88

99
build:
10-
@go build ./...
10+
@go build -o main

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
[![Build Status](https://travis-ci.org/infinityworks/github-exporter.svg?branch=master)](https://travis-ci.org/infinityworks/github-exporter)
1+
# :warning: This repository is moving to the [githubexporter](https://github.com/githubexporter) organisation at [githubexporter/github-exporter](https://github.com/githubexporter/github-exporter) :warning:
2+
3+
Timeline of changes:
4+
* 22/05/2023 - All current images are available in the new Docker Hub organisation at https://hub.docker.com/r/githubexporter/github-exporter
5+
* 30/05/2023 - GitHub repository will be migrated to https://github.com/githubexporter/github-exporter
6+
* 30/05/2023 - Any new images will be pushed to the `githubexporter` Docker Hub repository only
7+
* 21/08/2023 - All existing images will be removed from the `infinityworks/github-exporter` Docker Hub repository.
8+
* 30/08/2023 - The `infinityworks/github-exporter` Docker Hub repository will be deprecated
29

310
# Prometheus GitHub Exporter
411

@@ -11,7 +18,7 @@ This exporter is setup to take input from environment variables. All variables a
1118
* `ORGS` If supplied, the exporter will enumerate all repositories for that organization. Expected in the format "org1, org2".
1219
* `REPOS` If supplied, The repos you wish to monitor, expected in the format "user/repo1, user/repo2". Can be across different Github users/orgs.
1320
* `USERS` If supplied, the exporter will enumerate all repositories for that users. Expected in
14-
the format "user1, user2".
21+
the format "user1, user2".
1522
* `GITHUB_TOKEN` If supplied, enables the user to supply a github authentication token that allows the API to be queried more often. Optional, but recommended.
1623
* `GITHUB_TOKEN_FILE` If supplied _instead of_ `GITHUB_TOKEN`, enables the user to supply a path to a file containing a github authentication token that allows the API to be queried more often. Optional, but recommended.
1724
* `GITHUB_APP` If true , authenticates ass GitHub app to the API.
@@ -29,7 +36,7 @@ the format "user1, user2".
2936

3037
Run manually from Docker Hub:
3138
```
32-
docker run -d --restart=always -p 9171:9171 -e REPOS="infinityworks/ranch-eye, infinityworks/prom-conf" infinityworks/github-exporter
39+
docker run -d --restart=always -p 9171:9171 -e REPOS="infinityworks/ranch-eye, infinityworks/prom-conf" githubexporter/github-exporter
3340
```
3441

3542
Run manually from Docker Hub (With GitHub App):
@@ -52,7 +59,7 @@ github-exporter:
5259
- 9171
5360
ports:
5461
- 9171:9171
55-
image: infinityworks/github-exporter:latest
62+
image: githubexporter/github-exporter:latest
5663
environment:
5764
- REPOS=<REPOS you want to monitor>
5865
- GITHUB_TOKEN=<your github api token>
@@ -89,7 +96,7 @@ An example of these metrics can be found in the `METRICS.md` markdown file in th
8996

9097
## Tests
9198

92-
There is a set of blackbox behavioural tests which validate metrics endpoint in the `test` directory.
99+
There is a set of blackbox behavioural tests which validate metrics endpoint in the `test` directory.
93100
Run as follows
94101

95102
```bash
@@ -99,7 +106,7 @@ make test
99106
## Version Release Procedure
100107
Once a new pull request has been merged into `master` the following script should be executed locally. The script will trigger a new image build in docker hub with the new image having the tag `release-<version>`. The version is taken from the `VERSION` file and must follow semantic versioning. For more information see [semver.org](https://semver.org/).
101108

102-
Prior to running the following command ensure the number has been increased to desired version in `VERSION`:
109+
Prior to running the following command ensure the number has been increased to desired version in `VERSION`:
103110

104111
```bash
105112
./release-version.sh

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.3
1+
1.1.0

config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *Config) SetAPIToken(token string) {
132132

133133
// SetAPITokenFromFile accepts a file containing an oauth2 token for usage in http.request
134134
func (c *Config) SetAPITokenFromFile(tokenFile string) error {
135-
b, err := ioutil.ReadFile(tokenFile)
135+
b, err := os.ReadFile(tokenFile)
136136
if err != nil {
137137
return err
138138
}
@@ -181,6 +181,8 @@ func (c *Config) setScrapeURLs() error {
181181
}
182182

183183
// Append github orginisations to the array
184+
185+
184186
if len(c.organisations) > 0 {
185187
for _, x := range c.organisations {
186188
y := *c.apiUrl

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- 9171
99
ports:
1010
- 9171:9171
11-
image: infinityworks/github-exporter:latest
11+
image: githubexporter/github-exporter:latest
1212
environment:
1313
- REPOS=<REPOS you want to monitor>
1414
- GITHUB_TOKEN=<your github api token>

exporter/http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package exporter
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
neturl "net/url"
88
"strconv"
@@ -40,7 +40,7 @@ func asyncHTTPGets(targets []string, token string) ([]*Response, error) {
4040
case r := <-ch:
4141
if r.err != nil {
4242
log.Errorf("Error scraping API, Error: %v", r.err)
43-
break
43+
return nil, r.err
4444
}
4545
responses = append(responses, r)
4646

@@ -111,7 +111,7 @@ func getResponse(url string, token string, ch chan<- *Response) error {
111111
defer resp.Body.Close()
112112

113113
// Read the body to a byte array so it can be used elsewhere
114-
body, err := ioutil.ReadAll(resp.Body)
114+
body, err := io.ReadAll(resp.Body)
115115
if err != nil {
116116
return fmt.Errorf("Error converting body to byte array: %v", err)
117117
}

exporter/metrics.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package exporter
22

3-
import "github.com/prometheus/client_golang/prometheus"
4-
import "strconv"
3+
import (
4+
"strconv"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
58

69
// AddMetrics - Add's all of the metrics to a map of strings, returns the map.
710
func AddMetrics() map[string]*prometheus.Desc {
@@ -21,7 +24,7 @@ func AddMetrics() map[string]*prometheus.Desc {
2124
APIMetrics["PullRequestCount"] = prometheus.NewDesc(
2225
prometheus.BuildFQName("github", "repo", "pull_request_count"),
2326
"Total number of pull requests for given repository",
24-
[]string{"repo"}, nil,
27+
[]string{"repo", "user"}, nil,
2528
)
2629
APIMetrics["Watchers"] = prometheus.NewDesc(
2730
prometheus.BuildFQName("github", "repo", "watchers"),
@@ -41,7 +44,7 @@ func AddMetrics() map[string]*prometheus.Desc {
4144
APIMetrics["ReleaseDownloads"] = prometheus.NewDesc(
4245
prometheus.BuildFQName("github", "repo", "release_downloads"),
4346
"Download count for a given release",
44-
[]string{"repo", "user", "release", "name", "created_at"}, nil,
47+
[]string{"repo", "user", "release", "name", "tag", "created_at"}, nil,
4548
)
4649
APIMetrics["Limit"] = prometheus.NewDesc(
4750
prometheus.BuildFQName("github", "rate", "limit"),
@@ -74,7 +77,7 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr
7477

7578
for _, release := range x.Releases {
7679
for _, asset := range release.Assets {
77-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["ReleaseDownloads"], prometheus.GaugeValue, float64(asset.Downloads), x.Name, x.Owner.Login, release.Name, asset.Name, asset.CreatedAt)
80+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["ReleaseDownloads"], prometheus.GaugeValue, float64(asset.Downloads), x.Name, x.Owner.Login, release.Name, asset.Name, release.Tag, asset.CreatedAt)
7881
}
7982
}
8083
prCount := 0
@@ -85,7 +88,7 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr
8588
ch <- prometheus.MustNewConstMetric(e.APIMetrics["OpenIssues"], prometheus.GaugeValue, (x.OpenIssues - float64(prCount)), x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
8689

8790
// prCount
88-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["PullRequestCount"], prometheus.GaugeValue, float64(prCount), x.Name)
91+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["PullRequestCount"], prometheus.GaugeValue, float64(prCount), x.Name, x.Owner.Login)
8992
}
9093

9194
// Set Rate limit stats

0 commit comments

Comments
 (0)