Skip to content

Commit

Permalink
add explicit request source type to label the external request like l…
Browse files Browse the repository at this point in the history
…ightning/br

Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Jul 4, 2023
1 parent fbec023 commit 16dabbc
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions util/request_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 16dabbc

Please sign in to comment.