Skip to content

Commit b5ef07f

Browse files
committed
refactor(http): use strings.Cut for URL sanitization
Replaces the usage of `strings.IndexByte` with the more idiomatic Go function `strings.Cut`. This function is specifically designed to split a string into two parts based on a separator, making the code for redacting URL query parameters clearer and more expressive. fix(test): remove parallel execution to fix flaky telemetry tests The telemetry tests in `withTelemetry_test.go` modify shared global state related to the metrics collector. Running them with `t.Parallel()` created a race condition, leading to intermittent test failures. Removing `t.Parallel()` forces these tests to run sequentially, eliminating the race condition and stabilizing the test suite. A short sleep was also added to the reset function to ensure the collector has sufficient time to shut down before the next test starts. style(test): align struct field values in multi tenant test Adjusts code formatting in `multi_tenant_test.go` for better readability by aligning the values in a struct literal. This is a purely cosmetic change with no functional impact.
1 parent 9614832 commit b5ef07f

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

commons/net/http/withTelemetry_helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func sanitizeURL(rawURL string) string {
5858

5959
func sanitizeMalformedURL(rawURL string) string {
6060
sanitized := sanitizeLogValue(rawURL)
61-
if idx := strings.IndexByte(sanitized, '?'); idx >= 0 {
62-
return sanitized[:idx] + "?redacted"
61+
if before, _, ok := strings.Cut(sanitized, "?"); ok {
62+
return before + "?redacted"
6363
}
6464

6565
return sanitized

commons/net/http/withTelemetry_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func resetMetricsCollectorState() {
550550

551551
if metricsCollectorStarted && metricsCollectorShutdown != nil {
552552
close(metricsCollectorShutdown)
553+
time.Sleep(50 * time.Millisecond)
553554
}
554555

555556
metricsCollectorShutdown = nil
@@ -559,7 +560,6 @@ func resetMetricsCollectorState() {
559560
}
560561

561562
func TestEnsureMetricsCollector_ReturnsErrorWhenMetricsFactoryNil(t *testing.T) {
562-
t.Parallel()
563563
resetMetricsCollectorState()
564564
t.Cleanup(resetMetricsCollectorState)
565565

@@ -575,7 +575,6 @@ func TestEnsureMetricsCollector_ReturnsErrorWhenMetricsFactoryNil(t *testing.T)
575575
}
576576

577577
func TestEnsureMetricsCollector_NoMeterProviderReturnsNil(t *testing.T) {
578-
t.Parallel()
579578
resetMetricsCollectorState()
580579
t.Cleanup(resetMetricsCollectorState)
581580

@@ -585,7 +584,6 @@ func TestEnsureMetricsCollector_NoMeterProviderReturnsNil(t *testing.T) {
585584
}
586585

587586
func TestStopMetricsCollector_AllowsRestart(t *testing.T) {
588-
t.Parallel()
589587
resetMetricsCollectorState()
590588
t.Cleanup(resetMetricsCollectorState)
591589

commons/tenant-manager/consumer/multi_tenant_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,8 @@ func TestMultiTenantConsumer_NewWithZeroConfig(t *testing.T) {
889889
{
890890
name: "creates_pmClient_when_URL_configured",
891891
config: MultiTenantConfig{
892-
MultiTenantURL: "https://tenant-manager:4003",
893-
ServiceAPIKey: "test-key",
892+
MultiTenantURL: "https://tenant-manager:4003",
893+
ServiceAPIKey: "test-key",
894894
},
895895
expectedSync: 30 * time.Second,
896896
expectedWorkers: 0, // WorkersPerQueue is deprecated, default is 0

0 commit comments

Comments
 (0)