diff --git a/.gitignore b/.gitignore index 8d9be68..d12f528 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.tar.gz *.test *-stamp +artifactory_exporter diff --git a/Dockerfile b/Dockerfile index f0e32a1..c969e83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13 as build +FROM golang:1.15 as build WORKDIR /go/artifactory_exporter ADD . /go/artifactory_exporter diff --git a/artifactory/replication.go b/artifactory/replication.go index 312dd94..fc83cec 100644 --- a/artifactory/replication.go +++ b/artifactory/replication.go @@ -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 { diff --git a/artifactory/utils.go b/artifactory/utils.go index 87060f4..ff4d9ba 100644 --- a/artifactory/utils.go +++ b/artifactory/utils.go @@ -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) diff --git a/go.mod b/go.mod index 7ab2102..074fd0e 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 4aa39a4..44c0a20 100644 --- a/go.sum +++ b/go.sum @@ -19,12 +19,14 @@ 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= @@ -32,7 +34,9 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u 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=