diff --git a/src/query/api/v1/handler/database/config_bootstrappers_get.go b/src/query/api/v1/handler/database/config_bootstrappers_get.go index e3ee9ac4e4..885941f2b2 100644 --- a/src/query/api/v1/handler/database/config_bootstrappers_get.go +++ b/src/query/api/v1/handler/database/config_bootstrappers_get.go @@ -61,7 +61,7 @@ func (h *configGetBootstrappersHandler) ServeHTTP(w http.ResponseWriter, r *http store, err := h.client.KV() if err != nil { - logger.Error("unable to get kv store", zap.Any("error", err)) + logger.Error("unable to get kv store", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } @@ -72,14 +72,14 @@ func (h *configGetBootstrappersHandler) ServeHTTP(w http.ResponseWriter, r *http return } if err != nil { - logger.Error("unable to get kv key", zap.Any("error", err)) + logger.Error("unable to get kv key", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } array := new(commonpb.StringArrayProto) if err := value.Unmarshal(array); err != nil { - logger.Error("unable to unmarshal kv key", zap.Any("error", err)) + logger.Error("unable to unmarshal kv key", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/database/config_bootstrappers_set.go b/src/query/api/v1/handler/database/config_bootstrappers_set.go index 02a90edc64..61dc136b9b 100644 --- a/src/query/api/v1/handler/database/config_bootstrappers_set.go +++ b/src/query/api/v1/handler/database/config_bootstrappers_set.go @@ -63,20 +63,20 @@ func (h *configSetBootstrappersHandler) ServeHTTP(w http.ResponseWriter, r *http value, rErr := h.parseRequest(r) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } store, err := h.client.KV() if err != nil { - logger.Error("unable to get kv store", zap.Any("error", err)) + logger.Error("unable to get kv store", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } if _, err := store.Set(kvconfig.BootstrapperKey, value); err != nil { - logger.Error("unable to set kv key", zap.Any("error", err)) + logger.Error("unable to set kv key", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/database/create.go b/src/query/api/v1/handler/database/create.go index 8c8fac3478..db2cc6fd6f 100644 --- a/src/query/api/v1/handler/database/create.go +++ b/src/query/api/v1/handler/database/create.go @@ -171,7 +171,7 @@ func (h *createHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { parsedReq, namespaceRequest, placementRequest, rErr := h.parseAndValidateRequest(r, currPlacement) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } @@ -215,7 +215,7 @@ func (h *createHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { placementProto, err := currPlacement.Proto() if err != nil { - logger.Error("unable to get placement protobuf", zap.Any("error", err)) + logger.Error("unable to get placement protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/json/write.go b/src/query/api/v1/handler/json/write.go index 7428e48d07..b5fc34753a 100644 --- a/src/query/api/v1/handler/json/write.go +++ b/src/query/api/v1/handler/json/write.go @@ -77,12 +77,18 @@ func (h *WriteJSONHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { writeQuery, err := newStorageWriteQuery(req) if err != nil { - logging.WithContext(r.Context()).Error("Parsing error", zap.Any("err", err)) + logger := logging.WithContext(r.Context()) + logger.Error("parsing error", + zap.String("remoteAddr", r.RemoteAddr), + zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) } if err := h.store.Write(r.Context(), writeQuery); err != nil { - logging.WithContext(r.Context()).Error("Write error", zap.Any("err", err)) + logger := logging.WithContext(r.Context()) + logger.Error("write error", + zap.String("remoteAddr", r.RemoteAddr), + zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) } } diff --git a/src/query/api/v1/handler/json/write_test.go b/src/query/api/v1/handler/json/write_test.go index 20d2247661..d0b106f8b0 100644 --- a/src/query/api/v1/handler/json/write_test.go +++ b/src/query/api/v1/handler/json/write_test.go @@ -21,8 +21,12 @@ package json import ( + "bytes" "context" + "fmt" + "io/ioutil" "net/http" + "net/http/httptest" "strings" "testing" @@ -96,3 +100,37 @@ func TestJSONWrite(t *testing.T) { writeErr := jsonWrite.store.Write(context.TODO(), writeQuery) require.NoError(t, writeErr) } + +func TestJSONWriteError(t *testing.T) { + logging.InitWithCores(nil) + + expectedErr := fmt.Errorf("an error") + + ctrl := gomock.NewController(t) + storage, session := m3.NewStorageAndSession(t, ctrl) + session.EXPECT(). + WriteTagged(gomock.Any(), gomock.Any(), gomock.Any(), + gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + AnyTimes(). + Return(expectedErr) + session.EXPECT().IteratorPools(). + Return(nil, nil).AnyTimes() + + jsonWrite := &WriteJSONHandler{store: storage} + + jsonReq := generateJSONWriteRequest() + req, err := http.NewRequest(JSONWriteHTTPMethod, WriteJSONURL, + strings.NewReader(jsonReq)) + require.NoError(t, err) + + writer := httptest.NewRecorder() + jsonWrite.ServeHTTP(writer, req) + resp := writer.Result() + require.Equal(t, http.StatusInternalServerError, resp.StatusCode) + + body, err := ioutil.ReadAll(resp.Body) + require.NoError(t, err) + + require.True(t, bytes.Contains(body, []byte(expectedErr.Error())), + fmt.Sprintf("body: %s", body)) +} diff --git a/src/query/api/v1/handler/namespace/add.go b/src/query/api/v1/handler/namespace/add.go index 7a5b606325..1d509dd155 100644 --- a/src/query/api/v1/handler/namespace/add.go +++ b/src/query/api/v1/handler/namespace/add.go @@ -68,7 +68,7 @@ func (h *AddHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { md, rErr := h.parseRequest(r) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } @@ -82,7 +82,7 @@ func (h *AddHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - logger.Error("unable to get namespace", zap.Any("error", err)) + logger.Error("unable to get namespace", zap.Error(err)) xhttp.Error(w, err, http.StatusBadRequest) return } diff --git a/src/query/api/v1/handler/namespace/delete.go b/src/query/api/v1/handler/namespace/delete.go index 29bf70425b..3467027192 100644 --- a/src/query/api/v1/handler/namespace/delete.go +++ b/src/query/api/v1/handler/namespace/delete.go @@ -77,14 +77,14 @@ func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { logger := logging.WithContext(ctx) id := strings.TrimSpace(mux.Vars(r)[namespaceIDVar]) if id == "" { - logger.Error("no namespace ID to delete", zap.Any("error", errEmptyID)) + logger.Error("no namespace ID to delete", zap.Error(errEmptyID)) xhttp.Error(w, errEmptyID, http.StatusBadRequest) return } err := h.Delete(id) if err != nil { - logger.Error("unable to delete namespace", zap.Any("error", err)) + logger.Error("unable to delete namespace", zap.Error(err)) if err == errNamespaceNotFound { xhttp.Error(w, err, http.StatusNotFound) } else { diff --git a/src/query/api/v1/handler/namespace/get.go b/src/query/api/v1/handler/namespace/get.go index c2723561c6..6b5c2809fa 100644 --- a/src/query/api/v1/handler/namespace/get.go +++ b/src/query/api/v1/handler/namespace/get.go @@ -62,7 +62,7 @@ func (h *GetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { nsRegistry, err := h.Get() if err != nil { - logger.Error("unable to get namespace", zap.Any("error", err)) + logger.Error("unable to get namespace", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/openapi/openapi.go b/src/query/api/v1/handler/openapi/openapi.go index 0b2c67f29b..6be0e2515a 100644 --- a/src/query/api/v1/handler/openapi/openapi.go +++ b/src/query/api/v1/handler/openapi/openapi.go @@ -57,7 +57,7 @@ func (h *DocHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { doc, err := assets.FSByte(false, docPath) if err != nil { - logger.Error("unable to load doc", zap.Any("error", err)) + logger.Error("unable to load doc", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/placement/add.go b/src/query/api/v1/handler/placement/add.go index 408bbdfc9c..d577ed7403 100644 --- a/src/query/api/v1/handler/placement/add.go +++ b/src/query/api/v1/handler/placement/add.go @@ -82,14 +82,14 @@ func (h *AddHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r *htt if _, ok := err.(unsafeAddError); ok { status = http.StatusBadRequest } - logger.Error("unable to add placement", zap.Any("error", err)) + logger.Error("unable to add placement", zap.Error(err)) xhttp.Error(w, err, status) return } placementProto, err := placement.Proto() if err != nil { - logger.Error("unable to get placement protobuf", zap.Any("error", err)) + logger.Error("unable to get placement protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/placement/delete.go b/src/query/api/v1/handler/placement/delete.go index 713eca8ca1..08641ea803 100644 --- a/src/query/api/v1/handler/placement/delete.go +++ b/src/query/api/v1/handler/placement/delete.go @@ -80,7 +80,7 @@ func (h *DeleteHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r * ) if id == "" { - logger.Error("no placement ID provided to delete", zap.Any("error", errEmptyID)) + logger.Error("no placement ID provided to delete", zap.Error(errEmptyID)) xhttp.Error(w, errEmptyID, http.StatusBadRequest) return } @@ -108,7 +108,7 @@ func (h *DeleteHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r * if force { newPlacement, err = service.RemoveInstances(toRemove) if err != nil { - logger.Error("unable to delete instances", zap.Any("error", err)) + logger.Error("unable to delete instances", zap.Error(err)) xhttp.Error(w, err, http.StatusNotFound) return } @@ -151,7 +151,7 @@ func (h *DeleteHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r * placementProto, err := newPlacement.Proto() if err != nil { - logger.Error("unable to get placement protobuf", zap.Any("error", err)) + logger.Error("unable to get placement protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/placement/delete_all.go b/src/query/api/v1/handler/placement/delete_all.go index 1e9e213c8b..6e4f6280c2 100644 --- a/src/query/api/v1/handler/placement/delete_all.go +++ b/src/query/api/v1/handler/placement/delete_all.go @@ -79,7 +79,7 @@ func (h *DeleteAllHandler) ServeHTTP(serviceName string, w http.ResponseWriter, } if err := service.Delete(); err != nil { - logger.Error("unable to delete placement", zap.Any("error", err)) + logger.Error("unable to delete placement", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/placement/get.go b/src/query/api/v1/handler/placement/get.go index b0521cb864..9d4653d67d 100644 --- a/src/query/api/v1/handler/placement/get.go +++ b/src/query/api/v1/handler/placement/get.go @@ -92,7 +92,7 @@ func (h *GetHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r *htt placementProto, err := placement.Proto() if err != nil { - logger.Error("unable to get placement protobuf", zap.Any("error", err)) + logger.Error("unable to get placement protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/placement/init.go b/src/query/api/v1/handler/placement/init.go index 1ddecc406f..4c2227b865 100644 --- a/src/query/api/v1/handler/placement/init.go +++ b/src/query/api/v1/handler/placement/init.go @@ -83,14 +83,14 @@ func (h *InitHandler) ServeHTTP(serviceName string, w http.ResponseWriter, r *ht xhttp.Error(w, err, http.StatusConflict) return } - logger.Error("unable to initialize placement", zap.Any("error", err)) + logger.Error("unable to initialize placement", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } placementProto, err := placement.Proto() if err != nil { - logger.Error("unable to get placement protobuf", zap.Any("error", err)) + logger.Error("unable to get placement protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/prometheus/native/common.go b/src/query/api/v1/handler/prometheus/native/common.go index 38f54f7e1a..efae61a513 100644 --- a/src/query/api/v1/handler/prometheus/native/common.go +++ b/src/query/api/v1/handler/prometheus/native/common.go @@ -127,7 +127,7 @@ func parseParams(r *http.Request, timeoutOpts *prometheus.TimeoutOpts) (models.R if endExclusiveVal != "" { excludeEnd, err := strconv.ParseBool(endExclusiveVal) if err != nil { - logging.WithContext(r.Context()).Warn("unable to parse end inclusive flag", zap.Any("error", err)) + logging.WithContext(r.Context()).Warn("unable to parse end inclusive flag", zap.Error(err)) } params.IncludeEnd = !excludeEnd diff --git a/src/query/api/v1/handler/prometheus/remote/read.go b/src/query/api/v1/handler/prometheus/remote/read.go index d1e2a90d7a..696d413d6c 100644 --- a/src/query/api/v1/handler/prometheus/remote/read.go +++ b/src/query/api/v1/handler/prometheus/remote/read.go @@ -100,7 +100,7 @@ func (h *PromReadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { result, err := h.read(ctx, w, req, timeout) if err != nil { h.promReadMetrics.fetchErrorsServer.Inc(1) - logger.Error("unable to fetch data", zap.Any("error", err)) + logger.Error("unable to fetch data", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } @@ -112,7 +112,7 @@ func (h *PromReadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { data, err := proto.Marshal(resp) if err != nil { h.promReadMetrics.fetchErrorsServer.Inc(1) - logger.Error("unable to marshal read results to protobuf", zap.Any("error", err)) + logger.Error("unable to marshal read results to protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } @@ -123,7 +123,8 @@ func (h *PromReadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { compressed := snappy.Encode(nil, data) if _, err := w.Write(compressed); err != nil { h.promReadMetrics.fetchErrorsServer.Inc(1) - logger.Error("unable to encode read results to snappy", zap.Any("err", err)) + logger.Error("unable to encode read results to snappy", + zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/prometheus/remote/write.go b/src/query/api/v1/handler/prometheus/remote/write.go index 168c873449..854111b10e 100644 --- a/src/query/api/v1/handler/prometheus/remote/write.go +++ b/src/query/api/v1/handler/prometheus/remote/write.go @@ -102,7 +102,10 @@ func (h *PromWriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { err := h.write(r.Context(), req) if err != nil { h.promWriteMetrics.writeErrorsServer.Inc(1) - logging.WithContext(r.Context()).Error("Write error", zap.Any("err", err)) + logger := logging.WithContext(r.Context()) + logger.Error("write error", + zap.String("remoteAddr", r.RemoteAddr), + zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/prometheus/remote/write_test.go b/src/query/api/v1/handler/prometheus/remote/write_test.go index 83d3668509..f417e11569 100644 --- a/src/query/api/v1/handler/prometheus/remote/write_test.go +++ b/src/query/api/v1/handler/prometheus/remote/write_test.go @@ -21,7 +21,10 @@ package remote import ( + "bytes" "context" + "fmt" + "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -30,6 +33,7 @@ import ( "github.com/m3db/m3/src/cmd/services/m3coordinator/ingest" "github.com/m3db/m3/src/dbnode/x/metrics" "github.com/m3db/m3/src/query/api/v1/handler/prometheus/remote/test" + "github.com/m3db/m3/src/query/models" "github.com/m3db/m3/src/query/util/logging" xclock "github.com/m3db/m3/src/x/clock" @@ -72,6 +76,36 @@ func TestPromWrite(t *testing.T) { require.NoError(t, writeErr) } +func TestPromWriteError(t *testing.T) { + logging.InitWithCores(nil) + + anError := fmt.Errorf("an error") + + ctrl := gomock.NewController(t) + mockDownsamplerAndWriter := ingest.NewMockDownsamplerAndWriter(ctrl) + mockDownsamplerAndWriter.EXPECT(). + WriteBatch(gomock.Any(), gomock.Any()). + Return(anError) + + promWrite, err := NewPromWriteHandler(mockDownsamplerAndWriter, + models.NewTagOptions(), tally.NoopScope) + require.NoError(t, err) + + promReq := test.GeneratePromWriteRequest() + promReqBody := test.GeneratePromWriteRequestBody(t, promReq) + req, err := http.NewRequest("POST", PromWriteURL, promReqBody) + require.NoError(t, err) + + writer := httptest.NewRecorder() + promWrite.ServeHTTP(writer, req) + resp := writer.Result() + require.Equal(t, http.StatusInternalServerError, resp.StatusCode) + + body, err := ioutil.ReadAll(resp.Body) + require.NoError(t, err) + require.True(t, bytes.Contains(body, []byte(anError.Error()))) +} + func TestWriteErrorMetricCount(t *testing.T) { logging.InitWithCores(nil) diff --git a/src/query/api/v1/handler/search.go b/src/query/api/v1/handler/search.go index 4229970821..1daf1a4df5 100644 --- a/src/query/api/v1/handler/search.go +++ b/src/query/api/v1/handler/search.go @@ -59,7 +59,7 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { query, rErr := h.parseBody(r) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } @@ -67,7 +67,7 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { results, err := h.search(r.Context(), query, opts) if err != nil { - logger.Error("unable to fetch data", zap.Any("error", err)) + logger.Error("unable to fetch data", zap.Error(err)) xhttp.Error(w, err, http.StatusBadRequest) return } diff --git a/src/query/api/v1/handler/topic/add.go b/src/query/api/v1/handler/topic/add.go index eac72b6777..bca7477cca 100644 --- a/src/query/api/v1/handler/topic/add.go +++ b/src/query/api/v1/handler/topic/add.go @@ -58,49 +58,49 @@ func (h *AddHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ) rErr := parseRequest(r, &req) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } service, err := h.serviceFn(h.client) if err != nil { - logger.Error("unable to get service", zap.Any("error", err)) + logger.Error("unable to get service", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } t, err := service.Get(topicName(r.Header)) if err != nil { - logger.Error("unable to get topic", zap.Any("error", err)) + logger.Error("unable to get topic", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } cs, err := topic.NewConsumerServiceFromProto(req.ConsumerService) if err != nil { - logger.Error("unable to parse consumer service", zap.Any("error", err)) + logger.Error("unable to parse consumer service", zap.Error(err)) xhttp.Error(w, err, http.StatusBadRequest) return } t, err = t.AddConsumerService(cs) if err != nil { - logger.Error("unable to add consumer service", zap.Any("error", err)) + logger.Error("unable to add consumer service", zap.Error(err)) xhttp.Error(w, err, http.StatusBadRequest) return } t, err = service.CheckAndSet(t, t.Version()) if err != nil { - logger.Error("unable to persist consumer service", zap.Any("error", err)) + logger.Error("unable to persist consumer service", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } topicProto, err := topic.ToProto(t) if err != nil { - logger.Error("unable to get topic protobuf", zap.Any("error", err)) + logger.Error("unable to get topic protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/topic/get.go b/src/query/api/v1/handler/topic/get.go index df06f73dc9..4d19157fde 100644 --- a/src/query/api/v1/handler/topic/get.go +++ b/src/query/api/v1/handler/topic/get.go @@ -58,21 +58,21 @@ func (h *GetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { service, err := h.serviceFn(h.client) if err != nil { - logger.Error("unable to get service", zap.Any("error", err)) + logger.Error("unable to get service", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } t, err := service.Get(topicName(r.Header)) if err != nil { - logger.Error("unable to get topic", zap.Any("error", err)) + logger.Error("unable to get topic", zap.Error(err)) xhttp.Error(w, err, http.StatusNotFound) return } pb, err := topic.ToProto(t) if err != nil { - logger.Error("unable to get topic protobuf", zap.Any("error", err)) + logger.Error("unable to get topic protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/api/v1/handler/topic/init.go b/src/query/api/v1/handler/topic/init.go index 13a357a00a..bce34832ac 100644 --- a/src/query/api/v1/handler/topic/init.go +++ b/src/query/api/v1/handler/topic/init.go @@ -58,14 +58,14 @@ func (h *InitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ) rErr := parseRequest(r, &req) if rErr != nil { - logger.Error("unable to parse request", zap.Any("error", rErr)) + logger.Error("unable to parse request", zap.Error(rErr)) xhttp.Error(w, rErr.Inner(), rErr.Code()) return } service, err := h.serviceFn(h.client) if err != nil { - logger.Error("unable to get service", zap.Any("error", err)) + logger.Error("unable to get service", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } @@ -75,14 +75,14 @@ func (h *InitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { SetNumberOfShards(req.NumberOfShards) t, err = service.CheckAndSet(t, 0) if err != nil { - logger.Error("unable to init topic", zap.Any("error", err)) + logger.Error("unable to init topic", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } topicProto, err := topic.ToProto(t) if err != nil { - logger.Error("unable to get topic protobuf", zap.Any("error", err)) + logger.Error("unable to get topic protobuf", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return } diff --git a/src/query/benchmark/benchmarker/main/benchmarker.go b/src/query/benchmark/benchmarker/main/benchmarker.go index c976384cd4..65311cd0a8 100644 --- a/src/query/benchmark/benchmarker/main/benchmarker.go +++ b/src/query/benchmark/benchmarker/main/benchmarker.go @@ -86,7 +86,7 @@ func main() { logger.Info("Calculating cardinality only") cardinality, err := calculateCardinality(inputFile, logger) if err != nil { - logger.Fatal("cannot get cardinality", zap.Any("err", err)) + logger.Fatal("cannot get cardinality", zap.Error(err)) return } logger.Info("Cardinality", zap.String("dataFile", dataFile), zap.Int("cardinality", cardinality)) @@ -99,7 +99,7 @@ func main() { lines, err := convertToProm(inputFile, dataDir, dataFile, workers, batch, logger) if err != nil { - logger.Fatal("cannot convert to prom", zap.Any("err", err)) + logger.Fatal("cannot convert to prom", zap.Error(err)) return } metricsToWrite = lines @@ -107,7 +107,7 @@ func main() { logger.Info("Benchmarking writes on m3coordinator over http endpoint...") err := benchmarkCoordinator(metricsToWrite) if err != nil { - logger.Fatal("cannot benchmark coordinator to prom", zap.Any("err", err)) + logger.Fatal("cannot benchmark coordinator to prom", zap.Error(err)) return } diff --git a/src/query/server/server.go b/src/query/server/server.go index 692b855c9a..338e839a05 100644 --- a/src/query/server/server.go +++ b/src/query/server/server.go @@ -137,7 +137,7 @@ func Run(runOpts RunOptions) { scope, closer, err := cfg.Metrics.NewRootScope() if err != nil { - logger.Fatal("could not connect to metrics", zap.Any("error", err)) + logger.Fatal("could not connect to metrics", zap.Error(err)) } tracer, traceCloser, err := cfg.Tracing.NewTracer(serviceName, scope, logger) diff --git a/src/x/net/http/response.go b/src/x/net/http/response.go index 9d0a669f92..e31a1a10c9 100644 --- a/src/x/net/http/response.go +++ b/src/x/net/http/response.go @@ -34,7 +34,7 @@ import ( func WriteJSONResponse(w http.ResponseWriter, data interface{}, logger *zap.Logger) { jsonData, err := json.Marshal(data) if err != nil { - logger.Error("unable to marshal json", zap.Any("error", err)) + logger.Error("unable to marshal json", zap.Error(err)) Error(w, err, http.StatusInternalServerError) return } @@ -51,7 +51,7 @@ func WriteProtoMsgJSONResponse(w http.ResponseWriter, data proto.Message, logger w.Header().Set("Content-Type", "application/json") err := marshaler.Marshal(w, data) if err != nil { - logger.Error("unable to marshal json", zap.Any("error", err)) + logger.Error("unable to marshal json", zap.Error(err)) Error(w, err, http.StatusInternalServerError) } }