Skip to content

Commit

Permalink
Ignore replication endpoint if it doesn't exist (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
peimanja authored Feb 1, 2021
1 parent aa959af commit 2fa9577
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.tar.gz
*.test
*-stamp
artifactory_exporter
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13 as build
FROM golang:1.15 as build

WORKDIR /go/artifactory_exporter
ADD . /go/artifactory_exporter
Expand Down
3 changes: 3 additions & 0 deletions artifactory/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (c *Client) FetchReplications() ([]Replication, error) {
level.Debug(c.logger).Log("msg", "Fetching replications stats")
resp, err := c.FetchHTTP(replicationEndpoint)
if err != nil {
if err.(*APIError).status == 404 {
return replications, nil
}
return nil, err
}
if err := json.Unmarshal(resp, &replications); err != nil {
Expand Down
18 changes: 18 additions & 0 deletions artifactory/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ func (c *Client) FetchHTTP(path string) ([]byte, error) {
}
defer resp.Body.Close()

if resp.StatusCode == 404 {
var apiErrors APIErrors
bodyBytes, _ := ioutil.ReadAll(resp.Body)
if err := json.Unmarshal(bodyBytes, &apiErrors); err != nil {
level.Error(c.logger).Log("msg", "There was an error when trying to unmarshal the API Error", "err", err)
return nil, &UnmarshalError{
message: err.Error(),
endpoint: fullPath,
}
}
level.Warn(c.logger).Log("msg", "The endpoint does not exist", "endpoint", fullPath, "err", fmt.Sprintf("%v", apiErrors.Errors), "status", 404)
return nil, &APIError{
message: fmt.Sprintf("%v", apiErrors.Errors),
endpoint: fullPath,
status: 404,
}
}

if !(resp.StatusCode >= 200 && resp.StatusCode < 300) {
var apiErrors APIErrors
bodyBytes, _ := ioutil.ReadAll(resp.Body)
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
module github.com/peimanja/artifactory_exporter

go 1.12
go 1.15

require (
github.com/go-kit/kit v0.9.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/prometheus/client_golang v1.3.0
github.com/prometheus/common v0.7.0
github.com/sirupsen/logrus v1.4.2
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand Down

0 comments on commit 2fa9577

Please sign in to comment.