-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Anonymize the host in case of HTTP failure (RabbitMQ Scaler) (#2041)
* Anonimize the host in case of HTTP failure Signed-off-by: jorturfer <[email protected]> * Update CHANGELOG and add one extra test case Signed-off-by: jorturfer <[email protected]> * Move the regex from the method to a static var Signed-off-by: jorturfer <[email protected]> * Update regex var name Co-authored-by: Zbynek Roubalik <[email protected]> Signed-off-by: Jorge Turrado <[email protected]> * Fix typo and improve test Co-authored-by: Aaron Schlesinger <[email protected]> Signed-off-by: jorturfer <[email protected]> Co-authored-by: Ahmed ElSayed <[email protected]>
- Loading branch information
1 parent
0e4a01f
commit ff19979
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import ( | |
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
|
@@ -388,3 +390,42 @@ func TestRabbitMQGetMetricSpecForScaling(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
type rabbitMQErrorTestData struct { | ||
err error | ||
message string | ||
} | ||
|
||
var anonimizeRabbitMQErrorTestData = []rabbitMQErrorTestData{ | ||
{fmt.Errorf("https://user1:[email protected]"), "error inspecting rabbitMQ: https://user:[email protected]"}, | ||
{fmt.Errorf("https://fdasr345_-:[email protected]"), "error inspecting rabbitMQ: https://user:[email protected]"}, | ||
{fmt.Errorf("https://user1:[email protected]"), "error inspecting rabbitMQ: https://user:[email protected]"}, | ||
{fmt.Errorf("https://fdakls_dsa:[email protected]"), "error inspecting rabbitMQ: https://user:[email protected]"}, | ||
{fmt.Errorf("fdasr345_-:[email protected]"), "error inspecting rabbitMQ: user:[email protected]"}, | ||
{fmt.Errorf("this user1:[email protected] fails"), "error inspecting rabbitMQ: this user:[email protected] fails"}, | ||
{fmt.Errorf("this https://user1:[email protected] fails also"), "error inspecting rabbitMQ: this https://user:[email protected] fails also"}, | ||
{fmt.Errorf("nothing to replace here"), "error inspecting rabbitMQ: nothing to replace here"}, | ||
{fmt.Errorf("the queue https://user1:[email protected]/api/virtual is unavailable"), "error inspecting rabbitMQ: the queue https://user:[email protected]/api/virtual is unavailable"}, | ||
} | ||
|
||
func TestRabbitMQAnonimizeRabbitMQError(t *testing.T) { | ||
metadata := map[string]string{ | ||
"queueName": "evaluate_trials", | ||
"hostFromEnv": host, | ||
"protocol": "http", | ||
} | ||
meta, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) | ||
|
||
if err != nil { | ||
t.Fatalf("Error parsing metadata (%s)", err) | ||
} | ||
|
||
s := &rabbitMQScaler{ | ||
metadata: meta, | ||
httpClient: nil, | ||
} | ||
for _, testData := range anonimizeRabbitMQErrorTestData { | ||
err := s.anonimizeRabbitMQError(testData.err) | ||
assert.Equal(t, fmt.Sprint(err), testData.message) | ||
} | ||
} |