mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 02:48:59 +08:00
Fix/analytics (#2049)
* fix: incorrect calculation * chore: adding nil check Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
This commit is contained in:
parent
d1cc29e118
commit
153e859ac3
@ -30,6 +30,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/healthcheck"
|
"go.signoz.io/signoz/pkg/query-service/healthcheck"
|
||||||
basealm "go.signoz.io/signoz/pkg/query-service/integrations/alertManager"
|
basealm "go.signoz.io/signoz/pkg/query-service/integrations/alertManager"
|
||||||
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
|
baseint "go.signoz.io/signoz/pkg/query-service/interfaces"
|
||||||
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
pqle "go.signoz.io/signoz/pkg/query-service/pqlEngine"
|
pqle "go.signoz.io/signoz/pkg/query-service/pqlEngine"
|
||||||
rules "go.signoz.io/signoz/pkg/query-service/rules"
|
rules "go.signoz.io/signoz/pkg/query-service/rules"
|
||||||
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
||||||
@ -271,8 +272,9 @@ func (lrw *loggingResponseWriter) Flush() {
|
|||||||
|
|
||||||
func extractDashboardMetaData(path string, r *http.Request) (map[string]interface{}, bool) {
|
func extractDashboardMetaData(path string, r *http.Request) (map[string]interface{}, bool) {
|
||||||
pathToExtractBodyFrom := "/api/v2/metrics/query_range"
|
pathToExtractBodyFrom := "/api/v2/metrics/query_range"
|
||||||
var requestBody map[string]interface{}
|
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
var postData *model.QueryRangeParamsV2
|
||||||
|
|
||||||
if path == pathToExtractBodyFrom && (r.Method == "POST") {
|
if path == pathToExtractBodyFrom && (r.Method == "POST") {
|
||||||
if r.Body != nil {
|
if r.Body != nil {
|
||||||
@ -282,7 +284,8 @@ func extractDashboardMetaData(path string, r *http.Request) (map[string]interfac
|
|||||||
}
|
}
|
||||||
r.Body.Close() // must close
|
r.Body.Close() // must close
|
||||||
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
json.Unmarshal(bodyBytes, &requestBody)
|
json.Unmarshal(bodyBytes, &postData)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -291,31 +294,20 @@ func extractDashboardMetaData(path string, r *http.Request) (map[string]interfac
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
compositeMetricQuery, compositeMetricQueryExists := requestBody["compositeMetricQuery"]
|
signozMetricNotFound := false
|
||||||
|
|
||||||
signozMetricFound := false
|
if postData != nil {
|
||||||
|
signozMetricNotFound = telemetry.GetInstance().CheckSigNozMetricsV2(postData.CompositeMetricQuery)
|
||||||
|
|
||||||
if compositeMetricQueryExists {
|
if postData.CompositeMetricQuery != nil {
|
||||||
compositeMetricQueryMap := compositeMetricQuery.(map[string]interface{})
|
data["queryType"] = postData.CompositeMetricQuery.QueryType
|
||||||
|
data["panelType"] = postData.CompositeMetricQuery.PanelType
|
||||||
signozMetricFound = telemetry.GetInstance().CheckSigNozMetrics(compositeMetricQueryMap)
|
|
||||||
|
|
||||||
queryType, queryTypeExists := compositeMetricQueryMap["queryType"]
|
|
||||||
if queryTypeExists {
|
|
||||||
data["queryType"] = queryType
|
|
||||||
}
|
|
||||||
panelType, panelTypeExists := compositeMetricQueryMap["panelType"]
|
|
||||||
if panelTypeExists {
|
|
||||||
data["panelType"] = panelType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data["datasource"] = postData.DataSource
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource, datasourceExists := requestBody["dataSource"]
|
if signozMetricNotFound {
|
||||||
if datasourceExists {
|
|
||||||
data["datasource"] = datasource
|
|
||||||
}
|
|
||||||
|
|
||||||
if !signozMetricFound {
|
|
||||||
telemetry.GetInstance().AddActiveMetricsUser()
|
telemetry.GetInstance().AddActiveMetricsUser()
|
||||||
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_DASHBOARDS_METADATA, data, true)
|
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_DASHBOARDS_METADATA, data, true)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/healthcheck"
|
"go.signoz.io/signoz/pkg/query-service/healthcheck"
|
||||||
am "go.signoz.io/signoz/pkg/query-service/integrations/alertManager"
|
am "go.signoz.io/signoz/pkg/query-service/integrations/alertManager"
|
||||||
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
||||||
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
pqle "go.signoz.io/signoz/pkg/query-service/pqlEngine"
|
pqle "go.signoz.io/signoz/pkg/query-service/pqlEngine"
|
||||||
"go.signoz.io/signoz/pkg/query-service/rules"
|
"go.signoz.io/signoz/pkg/query-service/rules"
|
||||||
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
"go.signoz.io/signoz/pkg/query-service/telemetry"
|
||||||
@ -237,11 +238,11 @@ func (lrw *loggingResponseWriter) WriteHeader(code int) {
|
|||||||
func (lrw *loggingResponseWriter) Flush() {
|
func (lrw *loggingResponseWriter) Flush() {
|
||||||
lrw.ResponseWriter.(http.Flusher).Flush()
|
lrw.ResponseWriter.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractDashboardMetaData(path string, r *http.Request) (map[string]interface{}, bool) {
|
func extractDashboardMetaData(path string, r *http.Request) (map[string]interface{}, bool) {
|
||||||
pathToExtractBodyFrom := "/api/v2/metrics/query_range"
|
pathToExtractBodyFrom := "/api/v2/metrics/query_range"
|
||||||
var requestBody map[string]interface{}
|
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
var postData *model.QueryRangeParamsV2
|
||||||
|
|
||||||
if path == pathToExtractBodyFrom && (r.Method == "POST") {
|
if path == pathToExtractBodyFrom && (r.Method == "POST") {
|
||||||
if r.Body != nil {
|
if r.Body != nil {
|
||||||
@ -251,7 +252,8 @@ func extractDashboardMetaData(path string, r *http.Request) (map[string]interfac
|
|||||||
}
|
}
|
||||||
r.Body.Close() // must close
|
r.Body.Close() // must close
|
||||||
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
json.Unmarshal(bodyBytes, &requestBody)
|
json.Unmarshal(bodyBytes, &postData)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -260,31 +262,20 @@ func extractDashboardMetaData(path string, r *http.Request) (map[string]interfac
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
compositeMetricQuery, compositeMetricQueryExists := requestBody["compositeMetricQuery"]
|
signozMetricNotFound := false
|
||||||
|
|
||||||
signozMetricFound := false
|
if postData != nil {
|
||||||
|
signozMetricNotFound = telemetry.GetInstance().CheckSigNozMetricsV2(postData.CompositeMetricQuery)
|
||||||
|
|
||||||
if compositeMetricQueryExists {
|
if postData.CompositeMetricQuery != nil {
|
||||||
compositeMetricQueryMap := compositeMetricQuery.(map[string]interface{})
|
data["queryType"] = postData.CompositeMetricQuery.QueryType
|
||||||
|
data["panelType"] = postData.CompositeMetricQuery.PanelType
|
||||||
signozMetricFound = telemetry.GetInstance().CheckSigNozMetrics(compositeMetricQueryMap)
|
|
||||||
|
|
||||||
queryType, queryTypeExists := compositeMetricQueryMap["queryType"]
|
|
||||||
if queryTypeExists {
|
|
||||||
data["queryType"] = queryType
|
|
||||||
}
|
|
||||||
panelType, panelTypeExists := compositeMetricQueryMap["panelType"]
|
|
||||||
if panelTypeExists {
|
|
||||||
data["panelType"] = panelType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data["datasource"] = postData.DataSource
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource, datasourceExists := requestBody["dataSource"]
|
if signozMetricNotFound {
|
||||||
if datasourceExists {
|
|
||||||
data["datasource"] = datasource
|
|
||||||
}
|
|
||||||
|
|
||||||
if !signozMetricFound {
|
|
||||||
telemetry.GetInstance().AddActiveMetricsUser()
|
telemetry.GetInstance().AddActiveMetricsUser()
|
||||||
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_DASHBOARDS_METADATA, data, true)
|
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_DASHBOARDS_METADATA, data, true)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package telemetry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -73,21 +72,28 @@ func (a *Telemetry) IsSampled() bool {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (telemetry *Telemetry) CheckSigNozMetrics(compositeMetricQueryMap map[string]interface{}) bool {
|
func (telemetry *Telemetry) CheckSigNozMetricsV2(compositeQuery *model.CompositeMetricQuery) bool {
|
||||||
|
|
||||||
builderQueries, builderQueriesExists := compositeMetricQueryMap["builderQueries"]
|
signozMetricsNotFound := false
|
||||||
if builderQueriesExists {
|
|
||||||
builderQueriesStr, _ := json.Marshal(builderQueries)
|
if compositeQuery.BuilderQueries != nil && len(compositeQuery.BuilderQueries) > 0 {
|
||||||
return strings.Contains(string(builderQueriesStr), "signoz_")
|
if !strings.Contains(compositeQuery.BuilderQueries["A"].MetricName, "signoz_") && len(compositeQuery.BuilderQueries["A"].MetricName) > 0 {
|
||||||
|
signozMetricsNotFound = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
promQueries, promQueriesExists := compositeMetricQueryMap["promQueries"]
|
if compositeQuery.PromQueries != nil && len(compositeQuery.PromQueries) > 0 {
|
||||||
if promQueriesExists {
|
if !strings.Contains(compositeQuery.PromQueries["A"].Query, "signoz_") && len(compositeQuery.PromQueries["A"].Query) > 0 {
|
||||||
promQueriesStr, _ := json.Marshal(promQueries)
|
signozMetricsNotFound = true
|
||||||
return strings.Contains(string(promQueriesStr), "signoz_")
|
}
|
||||||
|
}
|
||||||
|
if compositeQuery.ClickHouseQueries != nil && len(compositeQuery.ClickHouseQueries) > 0 {
|
||||||
|
if !strings.Contains(compositeQuery.ClickHouseQueries["A"].Query, "signoz_") && len(compositeQuery.ClickHouseQueries["A"].Query) > 0 {
|
||||||
|
signozMetricsNotFound = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return signozMetricsNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (telemetry *Telemetry) AddActiveTracesUser() {
|
func (telemetry *Telemetry) AddActiveTracesUser() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user