mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 23:18:59 +08:00
feat: active user
This commit is contained in:
parent
aad962d07d
commit
c3253687d0
@ -1332,6 +1332,9 @@ func (aH *APIHandler) getServices(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_NUMBER_OF_SERVICES, data)
|
||||
if (data["number"] != 0) || (data["number"] != telemetry.DEFAULT_NUMBER_OF_SERVICES) {
|
||||
telemetry.GetInstance().AddActiveTracesUser()
|
||||
}
|
||||
|
||||
aH.WriteJSON(w, r, result)
|
||||
}
|
||||
|
@ -277,12 +277,27 @@ func extractDashboardMetaData(path string, r *http.Request) (map[string]interfac
|
||||
return data, true
|
||||
}
|
||||
|
||||
func getActiveMetricsOrLogs(path string, r *http.Request) {
|
||||
if path == "/api/v1/dashboards/{uuid}" {
|
||||
telemetry.GetInstance().AddActiveMetricsUser()
|
||||
}
|
||||
if path == "/api/v1/logs" {
|
||||
hasFilters := len(r.URL.Query().Get("q"))
|
||||
if hasFilters > 0 {
|
||||
telemetry.GetInstance().AddActiveLogsUser()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) analyticsMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
route := mux.CurrentRoute(r)
|
||||
path, _ := route.GetPathTemplate()
|
||||
|
||||
dashboardMetadata, metadataExists := extractDashboardMetaData(path, r)
|
||||
getActiveMetricsOrLogs(path, r)
|
||||
|
||||
lrw := NewLoggingResponseWriter(w)
|
||||
next.ServeHTTP(lrw, r)
|
||||
|
@ -35,12 +35,14 @@ const (
|
||||
TELEMETRY_EVENT_LOGS_FILTERS = "Logs Filters"
|
||||
TELEMETRY_EVENT_DISTRIBUTED = "Distributed"
|
||||
TELEMETRY_EVENT_DASHBOARDS_METADATA = "Dashboards Metadata"
|
||||
TELEMETRY_EVENT_ACTIVE_USER = "Active User"
|
||||
)
|
||||
|
||||
const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"
|
||||
const ph_api_key = "H-htDCae7CR3RV57gUzmol6IAKtm5IMCvbcm_fwnL-w"
|
||||
|
||||
const IP_NOT_FOUND_PLACEHOLDER = "NA"
|
||||
const DEFAULT_NUMBER_OF_SERVICES = 6
|
||||
|
||||
const HEART_BEAT_DURATION = 6 * time.Hour
|
||||
|
||||
@ -67,6 +69,16 @@ func (a *Telemetry) IsSampled() bool {
|
||||
|
||||
}
|
||||
|
||||
func (telemetry *Telemetry) AddActiveTracesUser() {
|
||||
telemetry.activeUser["traces"] = 1
|
||||
}
|
||||
func (telemetry *Telemetry) AddActiveMetricsUser() {
|
||||
telemetry.activeUser["metrics"] = 1
|
||||
}
|
||||
func (telemetry *Telemetry) AddActiveLogsUser() {
|
||||
telemetry.activeUser["logs"] = 1
|
||||
}
|
||||
|
||||
type Telemetry struct {
|
||||
operator analytics.Client
|
||||
phOperator ph.Client
|
||||
@ -79,6 +91,7 @@ type Telemetry struct {
|
||||
minRandInt int
|
||||
maxRandInt int
|
||||
rateLimits map[string]int8
|
||||
activeUser map[string]int8
|
||||
}
|
||||
|
||||
func createTelemetry() {
|
||||
@ -114,6 +127,13 @@ func createTelemetry() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
|
||||
if (telemetry.activeUser["traces"] != 0) || (telemetry.activeUser["metrics"] != 0) || (telemetry.activeUser["logs"] != 0) {
|
||||
telemetry.activeUser["any"] = 1
|
||||
}
|
||||
telemetry.SendEvent(TELEMETRY_EVENT_ACTIVE_USER, map[string]interface{}{"traces": telemetry.activeUser["traces"], "metrics": telemetry.activeUser["metrics"], "logs": telemetry.activeUser["logs"], "any": telemetry.activeUser["any"]})
|
||||
telemetry.activeUser = map[string]int8{"traces": 0, "metrics": 0, "logs": 0, "any": 0}
|
||||
|
||||
tagsInfo, _ := telemetry.reader.GetTagsInfoInLastHeartBeatInterval(context.Background())
|
||||
|
||||
if len(tagsInfo.Env) != 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user