mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-30 23:32:01 +08:00

* feat(inspect): added inspect metric api | 7076 * feat(inspect): added inspect metric api | 7076 * feat(inspect): added inspect metric api | 7076 * feat(inspect): removed underscore label keys * feat(explorer): updated metadata metrics api| 7076 * feat(explorer): added inspect metrics with resource attribute| 7076 * fix(summary): fixed dashboard name in metric metadata api * fix(summary): removed offset from second query * fix(summary): removed offset from second query * feat(inspect): normalized resource attributes --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
90 lines
3.2 KiB
Go
90 lines
3.2 KiB
Go
package metricsexplorer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
|
|
|
"go.signoz.io/signoz/pkg/query-service/model"
|
|
"go.signoz.io/signoz/pkg/query-service/model/metrics_explorer"
|
|
)
|
|
|
|
func ParseFilterKeySuggestions(r *http.Request) (*metrics_explorer.FilterKeyRequest, *model.ApiError) {
|
|
|
|
searchText := r.URL.Query().Get("searchText")
|
|
limit, err := strconv.Atoi(r.URL.Query().Get("limit"))
|
|
if err != nil {
|
|
limit = 50
|
|
}
|
|
|
|
return &metrics_explorer.FilterKeyRequest{Limit: limit, SearchText: searchText}, nil
|
|
}
|
|
|
|
func ParseFilterValueSuggestions(r *http.Request) (*metrics_explorer.FilterValueRequest, *model.ApiError) {
|
|
var filterValueRequest metrics_explorer.FilterValueRequest
|
|
|
|
// parse the request body
|
|
if err := json.NewDecoder(r.Body).Decode(&filterValueRequest); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
|
|
}
|
|
|
|
return &filterValueRequest, nil
|
|
}
|
|
|
|
func ParseSummaryListMetricsParams(r *http.Request) (*metrics_explorer.SummaryListMetricsRequest, *model.ApiError) {
|
|
var listMetricsParams *metrics_explorer.SummaryListMetricsRequest
|
|
|
|
// parse the request body
|
|
if err := json.NewDecoder(r.Body).Decode(&listMetricsParams); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
|
|
}
|
|
|
|
if listMetricsParams.OrderBy.ColumnName == "" || listMetricsParams.OrderBy.Order == "" {
|
|
listMetricsParams.OrderBy.ColumnName = "timeseries" // DEFAULT ORDER BY
|
|
listMetricsParams.OrderBy.Order = v3.DirectionDesc
|
|
}
|
|
|
|
if listMetricsParams.Limit == 0 {
|
|
listMetricsParams.Limit = 10 // DEFAULT LIMIT
|
|
}
|
|
|
|
return listMetricsParams, nil
|
|
}
|
|
|
|
func ParseTreeMapMetricsParams(r *http.Request) (*metrics_explorer.TreeMapMetricsRequest, *model.ApiError) {
|
|
var treeMapMetricParams *metrics_explorer.TreeMapMetricsRequest
|
|
|
|
// parse the request body
|
|
if err := json.NewDecoder(r.Body).Decode(&treeMapMetricParams); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
|
|
}
|
|
|
|
if treeMapMetricParams.Limit == 0 {
|
|
treeMapMetricParams.Limit = 10
|
|
}
|
|
|
|
return treeMapMetricParams, nil
|
|
}
|
|
|
|
func ParseRelatedMetricsParams(r *http.Request) (*metrics_explorer.RelatedMetricsRequest, *model.ApiError) {
|
|
var relatedMetricParams metrics_explorer.RelatedMetricsRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&relatedMetricParams); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
|
|
}
|
|
return &relatedMetricParams, nil
|
|
}
|
|
|
|
func ParseInspectMetricsParams(r *http.Request) (*metrics_explorer.InspectMetricsRequest, *model.ApiError) {
|
|
var inspectMetricParams metrics_explorer.InspectMetricsRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&inspectMetricParams); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
|
|
}
|
|
if inspectMetricParams.End-inspectMetricParams.Start > 1800000 { // half hour only
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("time duration shouldn't be more than 30 mins")}
|
|
}
|
|
return &inspectMetricParams, nil
|
|
}
|