Skip to content

Commit

Permalink
Merge pull request #1 from xxxcoltxxx/fix/request-close-body-on-error
Browse files Browse the repository at this point in the history
Fix/request close body on error
  • Loading branch information
xxxcoltxxx authored Dec 3, 2018
2 parents 8138a79 + a072696 commit 9962ff8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
/config.yaml
/dist
/balance_exporter
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: go
sudo: false
matrix:
include:
- go: 1.11.x

env:
- GO111MODULE=on

before_install:
- go get github.com/mitchellh/gox

script:
- go get -t -v ./...
- |-
gox \
-os="linux darwin windows" \
-arch="amd64" \
-output="dist/{{.Dir}}_${TRAVIS_TAG}_{{.OS}}_{{.Arch}}" \
-ldflags " \
-X github.com/prometheus/common/version.Revision=${TRAVIS_COMMIT} \
-X github.com/prometheus/common/version.Version=${TRAVIS_TAG} \
-X github.com/prometheus/common/version.Branch=${TRAVIS_BRANCH} \
-X github.com/prometheus/common/version.BuildDate=$(date +'%Y-%m-%d_%H:%M:%S') \
-X github.com/prometheus/common/version.BuildUser=${USER} \
"
before_deploy:
- cd dist
- chmod +x ./*
- for f in *; do tar -czf $f.tar.gz $f && rm $f; done
- cd ..

deploy:
provider: releases
api_key:
secure: y3wP/47D+Qee2HX2Vklz/V2gam57PXJoWVPQJc03Mdib9iWkfMAd4rmaI5kcCYSBnC18OGFHpV2bmXefoaNbdwhiC+ReDt3mSRlqfmaQMrt0T/g+r6rMb8KilCuH+OcXu7p7qP1C6aDRovIW6rX46IU6H1BYrOJRIajrI51Uxrv9yp4e2+0pYS67EIPSDUYPe41lxPky3Nq/gYzoMemzV/OckpkyBKE2tMXR3RXgH5ufZFXzhARH0hWTvkfJR58RtXneSsBQ733NX44fl8YYlYGi3wIkeiLCIcI+Mnpjj4nhhtHnaNR0S37qDGwV5oijwaNVJB3cEfg0E6f56ran9oEzx8i7lFTgdrF1r5D/ggPIwEJb9Kvnso2VkIEAVPuTJXTCuyou2woM5VOlIoV7UQndRkqP6F1h68gf+WaF2ju7nogqc8Cv91+M+aCaS0AJMxGGf6kgbADo/17pdxM4yMI95LtwFQNPq0gBpa5pgiWV7eGE0wksuA7CApRLdPk6wDx7bmjY59Q5x4uEOiU+ydUWyijIeFeC8rOfDLvnxDtX2uxpHbWX2Qd1v4L0HzKKsBPEIQgH9XEtN52Ls85bJXwjUxuvL2j76lyiINDjSBRaTr9myKkNan6JkryyWAZl/dIO7/RUBGkzjHWwSIh7Vz5RKtxB1OU7gN2DESum+G8=
file: build/*
on:
tags: true
repo: xxxcoltxxx/selectel-balance-exporter
11 changes: 8 additions & 3 deletions balance_retrievers/selectel.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,27 @@ func (bf SelectelBalanceRetriever) loadBody() ([]byte, error) {
req, err := http.NewRequest(http.MethodGet, selectelUrl, nil)

if err != nil {
log.Printf("Error fetching balance: %s", err.Error())
log.Printf("Error make request: %s", err.Error())
return []byte{}, err
}

req.Header.Add("X-token", bf.config.ApiKey)
res, err := client.Do(req)
if err != nil {
log.Printf("Error balance request: %s", err.Error())
return []byte{}, err
}

defer func() {
err := res.Body.Close()
if err != nil {
log.Printf("Error fetching balance: %s", err.Error())
log.Printf("Error close response body: %s", err.Error())
}
}()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Printf("Error fetching balance: %s", err.Error())
log.Printf("Error read response: %s", err.Error())
}

return body, nil
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
"github.com/spf13/viper"
"log"
"net/http"
Expand Down Expand Up @@ -51,7 +52,8 @@ func main() {
registerFetcher(balance_retrievers.NewSelectelBalanceFetcher(balance_retrievers.SelectelConfig{ApiKey: apiKey}))
}

log.Printf("Starting Selectel balance exporter at address %s\n", *addr)
log.Println("Starting Selectel balance exporter", version.Info())
log.Println("Build context", version.BuildContext())

loadBalance()

Expand Down

0 comments on commit 9962ff8

Please sign in to comment.