Skip to content

Commit fdcebae

Browse files
authored
Merge branch 'main' into profiles-cache
2 parents e663670 + e25b86e commit fdcebae

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

exporter/sumologicexporter/exporter.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (se *sumologicexporter) getHTTPClient() *http.Client {
281281

282282
func (se *sumologicexporter) setDataURLs(logs, metrics, traces string) {
283283
se.dataURLsLock.Lock()
284-
se.logger.Info("setting data urls", zap.String("logs_url", logs), zap.String("metrics_url", metrics), zap.String("traces_url", traces))
284+
se.logger.Info("setting data urls", zap.String("logs_url", sanitizeURL(logs)), zap.String("metrics_url", sanitizeURL(metrics)), zap.String("traces_url", sanitizeURL(traces)))
285285
se.dataURLLogs, se.dataURLMetrics, se.dataURLTraces = logs, metrics, traces
286286
se.dataURLsLock.Unlock()
287287
}
@@ -456,3 +456,31 @@ func getSignalURL(oCfg *Config, endpointURL string, signal pipeline.Signal) (str
456456

457457
return url.String(), nil
458458
}
459+
460+
func sanitizeURL(urlString string) string {
461+
strBefore := "otlp/"
462+
strAfter := "/v1/"
463+
leftIndex := strings.Index(urlString, strBefore)
464+
rightIndex := strings.LastIndex(urlString, strAfter)
465+
if leftIndex == -1 || rightIndex == -1 {
466+
return urlString
467+
}
468+
length := len(strBefore)
469+
checkSensitiveStrLen := (rightIndex - leftIndex) - length
470+
if checkSensitiveStrLen > 0 {
471+
s1 := urlString[0 : leftIndex+len(strBefore)]
472+
s2 := nchars('*', (rightIndex - leftIndex - length))
473+
s3 := urlString[rightIndex:]
474+
sanitizedStr := strings.Join([]string{s1, s2, s3}, "")
475+
return sanitizedStr
476+
}
477+
return urlString
478+
}
479+
480+
func nchars(b byte, n int) string {
481+
s := make([]byte, n)
482+
for i := range n {
483+
s[i] = b
484+
}
485+
return string(s)
486+
}

exporter/sumologicexporter/exporter_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,51 @@ func TestGetSignalURL(t *testing.T) {
648648
})
649649
}
650650
}
651+
652+
func TestNChars(t *testing.T) {
653+
s := nchars('*', 10)
654+
require.Equal(t, "**********", s)
655+
s = nchars(' ', 2)
656+
require.Equal(t, " ", s)
657+
}
658+
659+
func TestSanitizeURL(t *testing.T) {
660+
testCases := []struct {
661+
description string
662+
urlString string
663+
expected string
664+
}{
665+
{
666+
description: "sanitized logs url",
667+
urlString: "https://collectors.au.sumologic.com/receiver/v1/otlp/xxxxx/v1/logs",
668+
expected: "https://collectors.au.sumologic.com/receiver/v1/otlp/*****/v1/logs",
669+
},
670+
{
671+
description: "sanitized metrics url",
672+
urlString: "https://collectors.au.sumologic.com/receiver/v1/otlp/xxxx==/v1/metrics",
673+
expected: "https://collectors.au.sumologic.com/receiver/v1/otlp/******/v1/metrics",
674+
},
675+
{
676+
description: "sanitized traces url",
677+
urlString: "https://collectors.au.sumologic.com/receiver/v1/otlp/xxxx==/v1/traces",
678+
expected: "https://collectors.au.sumologic.com/receiver/v1/otlp/******/v1/traces",
679+
},
680+
{
681+
description: "no sanitization required",
682+
urlString: "https://collectors.au.sumologic.com/receiver/v1/xxxx==/v1/traces",
683+
expected: "https://collectors.au.sumologic.com/receiver/v1/xxxx==/v1/traces",
684+
},
685+
{
686+
description: "no sanitization required with otlp/ appearing after v1/",
687+
urlString: "https://collectors.au.sumologic.com/receiver/v1/v1/xxxx==/otlp/traces",
688+
expected: "https://collectors.au.sumologic.com/receiver/v1/v1/xxxx==/otlp/traces",
689+
},
690+
}
691+
for _, tC := range testCases {
692+
testCase := tC
693+
t.Run(tC.description, func(t *testing.T) {
694+
actual := sanitizeURL(testCase.urlString)
695+
require.Equal(t, testCase.expected, actual)
696+
})
697+
}
698+
}

0 commit comments

Comments
 (0)