Skip to content

Commit

Permalink
request_source: remove default label
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Jul 14, 2023
1 parent 85fc8f3 commit 036cbae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions util/request_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ const (
// explicit source types.
const (
ExplicitTypeEmpty = ""
ExplicitTypeDefault = "default"
ExplicitTypeLightning = "lightning"
ExplicitTypeBR = "br"
ExplicitTypeDumpling = "dumpling"
ExplicitTypeBackground = "background"
)

// ExplicitTypeList is the list of all explicit source types.
var ExplicitTypeList = []string{ExplicitTypeEmpty, ExplicitTypeDefault, ExplicitTypeLightning, ExplicitTypeBR, ExplicitTypeDumpling, ExplicitTypeBackground}
var ExplicitTypeList = []string{ExplicitTypeEmpty, ExplicitTypeLightning, ExplicitTypeBR, ExplicitTypeDumpling, ExplicitTypeBackground}

const (
// InternalRequest is the scope of internal queries
Expand Down Expand Up @@ -93,24 +92,28 @@ func IsRequestSourceInternal(reqSrc *RequestSource) bool {
// GetRequestSource gets the request_source field of the request.
func (r *RequestSource) GetRequestSource() string {
source := SourceUnknown
explicitSourceType := ExplicitTypeDefault
explicitSourceType := ExplicitTypeEmpty

Check failure on line 95 in util/request_source.go

View workflow job for this annotation

GitHub Actions / golangci

ineffectual assignment to explicitSourceType (ineffassign)
origin := ExternalRequest
if r == nil || (len(r.RequestSourceType) == 0 && len(r.ExplicitRequestSourceType) == 0) {
// if r.RequestSourceType and r.ExplicitRequestSourceType are not set, it's mostly possible that r.RequestSourceInternal is not set
// to avoid internal requests be marked as external(default value), return unknown source here.
return strings.Join([]string{source, explicitSourceType}, "_")
return source
}

if r.RequestSourceInternal {
origin = InternalRequest
}
labelList := make([]string, 0, 3)
labelList = append(labelList, origin)
if len(r.RequestSourceType) > 0 {
source = r.RequestSourceType
}
labelList = append(labelList, source)
if len(r.ExplicitRequestSourceType) > 0 {
explicitSourceType = r.ExplicitRequestSourceType
labelList = append(labelList, explicitSourceType)
}
if r.RequestSourceInternal {
origin = InternalRequest
}
return strings.Join([]string{origin, source, explicitSourceType}, "_")

return strings.Join(labelList, "_")
}

// RequestSourceFromCtx extract source from passed context.
Expand Down
6 changes: 3 additions & 3 deletions util/request_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func TestGetRequestSource(t *testing.T) {

// Test nil pointer
rs = nil
expected = "unknown_default"
expected = "unknown"
actual = rs.GetRequestSource()
assert.Equal(t, expected, actual)

// Test empty RequestSourceType and ExplicitRequestSourceType
rs = &RequestSource{}
expected = "unknown_default"
expected = "unknown"
actual = rs.GetRequestSource()
assert.Equal(t, expected, actual)

// Test empty ExplicitRequestSourceType
rs.RequestSourceType = "test"
expected = "external_test_default"
expected = "external_test"
actual = rs.GetRequestSource()
assert.Equal(t, expected, actual)

Expand Down

0 comments on commit 036cbae

Please sign in to comment.