Merge pull request #20 from navi-ppl/TP-55555/metrics-inclusion
TP-55555 | metrics inclusion
This commit is contained in:
@@ -3,9 +3,9 @@ package middleware
|
||||
import (
|
||||
"cybertron/constants"
|
||||
"cybertron/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
@@ -27,6 +27,18 @@ type UserInfo struct {
|
||||
|
||||
func PermissionMiddleware(authService *service.AuthService) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
excludedPublicUrls := []string{
|
||||
"/envelope",
|
||||
}
|
||||
|
||||
for _, url := range excludedPublicUrls {
|
||||
if strings.Contains(c.Request.RequestURI, url) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//println("%s", path.Base(c.Request.URL.Path))
|
||||
|
||||
sessionToken := c.GetHeader(constants.SESSION_HEADER_NAME)
|
||||
userEmail := c.GetHeader(constants.EMAIL_HEADER_NAME)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"cybertron/internal/transport/middleware"
|
||||
"cybertron/internal/transport/router"
|
||||
"cybertron/pkg/metrics"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -50,8 +52,10 @@ func (s *Server) Start() {
|
||||
AllowCredentials: true,
|
||||
MaxAge: 24 * time.Hour,
|
||||
}))
|
||||
s.gin.Use(middleware.MetricMiddleware())
|
||||
//s.gin.Use(middleware.PermissionMiddleware(s.dependencies.Service.AuthService))
|
||||
s.router()
|
||||
metrics.AdminHandler()
|
||||
|
||||
port := configs.GetPort()
|
||||
s.dependencies.Logger.Info("Starting server", zap.Int("port", port))
|
||||
|
||||
@@ -28,6 +28,10 @@ type ClientHttpCallMetric struct {
|
||||
DurationInMs int64 `json:"duration_in_ms,omitempty"`
|
||||
}
|
||||
|
||||
type ErrorConsumptionMetric struct {
|
||||
ProjectId string `json:"project_id,omitempty"`
|
||||
}
|
||||
|
||||
type MetricAttributes struct {
|
||||
ApiMetric ApiMetric
|
||||
ClientHttpCallMetric ClientHttpCallMetric
|
||||
|
||||
@@ -36,6 +36,10 @@ func publishApiMetric(apiMetrics instrumentation.ApiMetric) {
|
||||
ApiRequestLatencyHistogram.WithLabelValues(apiMetrics.Url, status).Observe(duration)
|
||||
}
|
||||
|
||||
func PublishErrorConsumptionMetric(errorConsumptionMetrics instrumentation.ErrorConsumptionMetric) {
|
||||
ErrorConsumerCounter.WithLabelValues(errorConsumptionMetrics.ProjectId).Inc()
|
||||
}
|
||||
|
||||
func publishClientHttpCallMetric(clientHttpCallMetric instrumentation.ClientHttpCallMetric) {
|
||||
status := strconv.Itoa(clientHttpCallMetric.ResponseCode)
|
||||
duration := float64(clientHttpCallMetric.DurationInMs)
|
||||
|
||||
@@ -15,6 +15,13 @@ var ApiRequestCounter = promauto.NewCounterVec(
|
||||
[]string{"url", "response_code"},
|
||||
)
|
||||
|
||||
var ErrorConsumerCounter = promauto.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "cybertron_error_consumption_counter_total",
|
||||
Help: "counter for number of error consumed by cybertron",
|
||||
},
|
||||
[]string{"project_id"},
|
||||
)
|
||||
var ApiRequestLatencyHistogram = promauto.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "cybertron_api_request_latency_histogram",
|
||||
|
||||
@@ -9,3 +9,7 @@ while read -r line; do
|
||||
echo "Building cybertron locally"
|
||||
eval "make build-cybertron
|
||||
$ENVS out/cybertron"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package service
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"cybertron/models/instrumentation"
|
||||
"cybertron/pkg/encoder"
|
||||
"cybertron/pkg/kafka/producer"
|
||||
"cybertron/pkg/log"
|
||||
"cybertron/pkg/metrics"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -37,7 +39,7 @@ type ExceptionValue struct {
|
||||
ProjectId string `json:"project_id,omitempty"`
|
||||
ReleaseId string `json:"release_id,omitempty"`
|
||||
Breadcrumbs interface{} `json:"breadcrumbs,omitempty"`
|
||||
Extras interface{} `json:"extras,omitempty"`
|
||||
Extra interface{} `json:"extra,omitempty"`
|
||||
Request interface{} `json:"request,omitempty"`
|
||||
}
|
||||
|
||||
@@ -63,6 +65,8 @@ func (exceptionService *ExceptionService) CatchErrors(c *gin.Context) {
|
||||
scanner := bufio.NewScanner(c.Request.Body)
|
||||
var lines []string
|
||||
|
||||
//error metric firing
|
||||
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
@@ -76,12 +80,14 @@ func (exceptionService *ExceptionService) CatchErrors(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
metrics.PublishErrorConsumptionMetric(instrumentation.ErrorConsumptionMetric{ProjectId: projectID})
|
||||
|
||||
for _, errorItem := range jsonData.Exception.Values {
|
||||
errorItem.ProjectId = projectID
|
||||
//todo update release id
|
||||
errorItem.ReleaseId = "release-1"
|
||||
errorItem.Breadcrumbs = jsonData.Breadcrumbs
|
||||
errorItem.Extras = jsonData.Extra
|
||||
errorItem.Extra = jsonData.Extra
|
||||
errorItem.Request = jsonData.Request
|
||||
err := exceptionService.kafkaProducer.PublishEvent(errorItem, "kafka-stream", "", nil, encoder.JsonEncoderInstance)
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ func (s *SearchService) GetErrorDetails(c *gin.Context) {
|
||||
|
||||
if err != nil {
|
||||
utils.ErrorResponse(c, "Failed to search please try again later")
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"results": response,
|
||||
|
||||
Reference in New Issue
Block a user