diff --git a/util/request_source.go b/util/request_source.go index eba974773..dd2addab3 100644 --- a/util/request_source.go +++ b/util/request_source.go @@ -29,9 +29,9 @@ const ( const ( // InternalRequest is the scope of internal queries - InternalRequest = "internal_" + InternalRequest = "internal" // ExternalRequest is the scope of external queries - ExternalRequest = "external_" + ExternalRequest = "external" // SourceUnknown keeps same with the default value(empty string) SourceUnknown = "unknown" ) @@ -40,6 +40,9 @@ const ( type RequestSource struct { RequestSourceInternal bool RequestSourceType string + // ExplicitRequestSoureType is set from the session variable `explicit_request_source_type`. it's a complement of RequestSourceType. + // The value maybe "lightning", "br", "dumpling" etc. + ExplicitRequestSoureType string } // SetRequestSourceInternal sets the scope of the request source. @@ -76,10 +79,24 @@ func (r *RequestSource) GetRequestSource() string { if r == nil || r.RequestSourceType == "" { return SourceUnknown } + appendType := func(list []string) []string { + if len(r.ExplicitRequestSoureType) > 0 { + list = append(list, r.ExplicitRequestSoureType) + return list + } + return list + } if r.RequestSourceInternal { - return InternalRequest + r.RequestSourceType + internalLabels := []string{InternalRequest, r.RequestSourceType} + internalLabels = appendType(internalLabels) + if len(r.ExplicitRequestSoureType) > 0 { + internalLabels = append(internalLabels, r.ExplicitRequestSoureType) + } + return strings.Join(internalLabels, "_") } - return ExternalRequest + r.RequestSourceType + internalLabels := []string{ExternalRequest, r.RequestSourceType} + internalLabels = appendType(internalLabels) + return strings.Join(internalLabels, "_") } // RequestSourceFromCtx extract source from passed context.