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