Skip to content

Commit

Permalink
Merge pull request #4 from ccremer/liveness
Browse files Browse the repository at this point in the history
Add liveness probe endpoint
  • Loading branch information
ccremer committed May 17, 2020
2 parents 2758b3b + bcfc380 commit a3e1708
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
47 changes: 41 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,40 @@ on:
pull_request:
types: [opened, reopened]

env:
GO_VERSION: "^1.14.3"

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2-beta
- uses: actions/setup-go@v2
with:
go-version: '^1.14.2'
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v1
with:
path: /home/runner/go/pkg/mod
key: go-mod-build
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: goreleaser/goreleaser-action@v1
with:
args: release --snapshot --skip-sign

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test & Publish Code Coverage
uses: paambaati/codeclimate-action@v2.6.0
env:
Expand All @@ -30,6 +52,19 @@ jobs:
prefix: ${{ github.event.repository.name }}
coverageLocations:
"${{github.workspace}}/c.out:gocov"
- uses: goreleaser/goreleaser-action@v1

formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
args: release --snapshot --skip-sign
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Verify if Code needs formatting
run: make fmt
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ on:
tags:
- "*"

env:
GO_VERSION: "^1.14.3"

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2-beta
- uses: actions/setup-go@v2
with:
go-version: '^1.14.2'
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v1
with:
path: /home/runner/go/pkg/mod
key: go-mod-release
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Login to Docker hub
run: docker login -u ${{ secrets.DOCKER_HUB_USER }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
- uses: goreleaser/goreleaser-action@v1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dist: fmt
clean:
@rm -rf fronius-exporter c.out dist

test: fmt
test:
@go test -coverprofile c.out ./...

run:
Expand Down
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,28 @@ func main() {
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
log.WithFields(log.Fields{
"uri": r.RequestURI,
"client": r.RemoteAddr,
}).Debug("Accessed Root endpoint")
http.Redirect(w, r, "/metrics", http.StatusMovedPermanently)
})
http.HandleFunc("/liveness", func(w http.ResponseWriter, r *http.Request) {
log.WithFields(log.Fields{
"uri": r.RequestURI,
"client": r.RemoteAddr,
}).Debug("Accessed Liveness endpoint")
w.WriteHeader(http.StatusNoContent)
})
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
log.WithFields(log.Fields{
"uri": r.RequestURI,
"client": r.RemoteAddr,
}).Debug("Accessed Metrics endpoint")
collectMetricsFromTarget(symoClient)
promHandler.ServeHTTP(w, r)
})
Expand Down

0 comments on commit a3e1708

Please sign in to comment.