Skip to content

Commit

Permalink
[Ajat|Baskara] push handler metrics to statsd
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jul 1, 2019
1 parent d85c5a7 commit 689816a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/handler/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"fmt"
"net/http"
"***REMOVED***/darkroom/core/pkg/metrics"

"***REMOVED***/darkroom/core/pkg/config"
"***REMOVED***/darkroom/core/pkg/logger"
Expand All @@ -12,13 +13,16 @@ import (
const (
ContentLengthHeader = "Content-Length"
CacheControlHeader = "Cache-Control"
StorageGetErrorKey = "handler.storage.get.error"
ProcessorErrorKey = "handler.processor.error"
)

func ImageHandler(deps *service.Dependencies) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res := deps.Storage.Get(r.Context(), r.URL.Path)
if res.Error() != nil {
logger.Errorf("error: %s", res.Error())
metrics.Update(metrics.UpdateOption{Name: StorageGetErrorKey, Type: metrics.Counter})
w.WriteHeader(res.Status())
return
}
Expand All @@ -37,6 +41,7 @@ func ImageHandler(deps *service.Dependencies) http.HandlerFunc {
data, err = deps.Manipulator.Process(r.Context(), data, params)
if err != nil {
logger.Errorf("error: %s", res.Error())
metrics.Update(metrics.UpdateOption{Name: ProcessorErrorKey, Type: metrics.Counter})
w.WriteHeader(http.StatusUnprocessableEntity)
return
}
Expand Down
1 change: 1 addition & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Type int
const (
Duration Type = 0
Guage Type = 1
Counter Type = 2
)

type UpdateOption struct {
Expand Down

0 comments on commit 689816a

Please sign in to comment.