added producer metrics, modified kafka write logic

This commit is contained in:
aishwarya-raimule
2023-01-12 12:59:22 +05:30
parent 755b85ef15
commit e940f69528
8 changed files with 95 additions and 30 deletions

View File

@@ -1,8 +1,11 @@
package server
import (
metrics "com.navi.medici.janus/instrumentation"
"com.navi.medici.janus/lib"
"com.navi.medici.janus/schema"
"com.navi.medici.janus/utils"
"time"
"compress/gzip"
"encoding/json"
@@ -16,6 +19,13 @@ var (
healthyBool bool = true
)
const (
JSON = "json"
PROTO = "proto"
SUCCESS = "success"
ERROR = "error"
)
type NewSchemaRequest struct {
Topic string `json:"topic"`
Schema string `json:"schema"`
@@ -65,6 +75,7 @@ func eventsHandler(w http.ResponseWriter, r *http.Request) {
}
func eventsHandlerJson(w http.ResponseWriter, r *http.Request) {
eventHandlerStartTime := utils.NanosToMillis(time.Now().UnixNano())
var reader io.Reader
// check if body is gzip compressed
if r.Header.Get("Content-Encoding") == "gzip" {
@@ -74,6 +85,7 @@ func eventsHandlerJson(w http.ResponseWriter, r *http.Request) {
// log.Printf(err)
w.Header().Set("Content-Type", "application/json")
http.Error(w, "Error while decompressing GZIP payload", http.StatusBadRequest)
metrics.EventHandlerTimeHist.WithLabelValues(JSON, ERROR).Observe(float64(utils.NanosToMillis(time.Now().UnixNano()) - eventHandlerStartTime))
return
}
} else {
@@ -85,14 +97,15 @@ func eventsHandlerJson(w http.ResponseWriter, r *http.Request) {
// log.Printf(err)
w.Header().Set("Content-Type", "application/json")
http.Error(w, "Request body invalid", http.StatusBadRequest)
metrics.EventHandlerTimeHist.WithLabelValues(JSON, ERROR).Observe(float64(utils.NanosToMillis(time.Now().UnixNano()) - eventHandlerStartTime))
return
}
w.Header().Set("Content-Type", "application/json")
lib.JsonRequestChannel <- &lib.RequestObject{Body: body, Header: r.Header}
//io.WriteString(w, "ok")
var rsp = CustomResponse{Code: 200, Message: "OK"}
json.NewEncoder(w).Encode(rsp)
metrics.EventHandlerTimeHist.WithLabelValues(JSON, SUCCESS).Observe(float64(utils.NanosToMillis(time.Now().UnixNano()) - eventHandlerStartTime))
}
func healthHandler(w http.ResponseWriter, r *http.Request) {