Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple metrics endpoint for rageshake. #82

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.20
- name: Install lint deps
run: |
go get golang.org/x/lint/golint
mkdir ~/go
go install golang.org/x/lint/golint
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go get github.com/fzipp/gocyclo/cmd/gocyclo
go install github.com/fzipp/gocyclo/cmd/gocyclo
- name: lint
run: ./scripts/lint.sh
test:
runs-on: ubuntu-latest
strategy:
matrix:
golang: ["1.17", "1.16"]
golang: ["1.21", "1.20"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.17
ARG GO_VERSION=1.20
ARG DEBIAN_VERSION=11
ARG DEBIAN_VERSION_NAME=bullseye

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ Optional parameters:
[rageshake.sample.yaml](rageshake.sample.yaml) for more information.
* `-listen <address>`: TCP network address to listen for HTTP requests
on. Example: `:9110`.
* `-metrics <address>`: TCP network address to listen for HTTP requests
for prometheus metrics on. Example: `:9111`. Defaults to not being served.

## HTTP endpoints

The following HTTP endpoints are exposed:

### GET `/health`

Returns a simple "ok" if the server is healthy, for use with automated healthchecks.

### GET `/api/listing/`

Serves submitted bug reports. Protected by basic HTTP auth using the
Expand Down Expand Up @@ -100,6 +106,10 @@ The response (if successful) will be a JSON object with the following fields:
* `report_url`: A URL where the user can track their bug report. Omitted if
issue submission was disabled.

### /metrics

If the metrics address is configured with `-metrics` then prometheus metrics are visible here.

## Notifications

You can get notifications when a new rageshake arrives on the server.
Expand Down
1 change: 1 addition & 0 deletions changelog.d/82.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new -metrics flag to optionally enable prometheus metrics listener.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ go 1.16
require (
github.com/google/go-github v0.0.0-20170401000335-12363ffc1001
github.com/jordan-wright/email v4.0.1-0.20200824153738-3f5bafa1cd84+incompatible
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/xanzy/go-gitlab v0.50.2
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288
gopkg.in/yaml.v2 v2.2.8
golang.org/x/oauth2 v0.8.0
golang.org/x/tools v0.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0
)
533 changes: 533 additions & 0 deletions go.sum

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
"time"

"github.com/google/go-github/github"
"github.com/xanzy/go-gitlab"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/xanzy/go-gitlab"
"golang.org/x/oauth2"

"gopkg.in/yaml.v2"
Expand All @@ -40,6 +41,8 @@ import (
var configPath = flag.String("config", "rageshake.yaml", "The path to the config file. For more information, see the config file in this repository.")
var bindAddr = flag.String("listen", ":9110", "The port to listen on.")

var metricsBindAddr = flag.String("metrics", "", "The port to listen on for metrics.")

type config struct {
// Username and password required to access the bug report listings
BugsUser string `yaml:"listings_auth_user"`
Expand Down Expand Up @@ -180,7 +183,14 @@ func main() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "ok")
})

if *metricsBindAddr != "" {
metricsMux := http.NewServeMux()
metricsMux.Handle("/metrics", promhttp.Handler())
go func() {
log.Println("Metrics Listening on", *metricsBindAddr)
http.ListenAndServe(*metricsBindAddr, metricsMux)
}()
}
log.Println("Listening on", *bindAddr)

log.Fatal(http.ListenAndServe(*bindAddr, nil))
Expand Down
Loading