cortex icon indicating copy to clipboard operation
cortex copied to clipboard

Fix panic on startup if the ExternalURL field in the ruler config is empty

Open kralicky opened this issue 1 year ago • 4 comments

If ExternalURL is "" in the ruler config, it will be unmarshaled into a nil *URL object, causing a nil pointer dereference when building the ruler config. The String() helper (which performs the correct nil-check) on the ExternalURL's wrapper type was likely intended to be used to obtain the url string, but the nested *URL struct's String() was called instead, causing a panic if it's nil.

What this PR does:

Which issue(s) this PR fixes: Fixes #

Checklist

  • [ ] Tests updated
  • [ ] Documentation added
  • [ ] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

kralicky avatar Aug 22 '23 22:08 kralicky

Nice catch.

Can you add a test for it? with a valid url as well?

alanprot avatar Aug 22 '23 22:08 alanprot

Sure thing :+1:

kralicky avatar Aug 23 '23 00:08 kralicky

I'm not sure exactly where a test for this would go - since there wasn't anything wrong with the URL wrapper code itself, just the usage, maybe it could be added in an integration test somewhere? Could you point me in the right direction?

kralicky avatar Aug 23 '23 00:08 kralicky

We can try to create a a config with a problematic entry and run the test (make sure we dont throw an error).

A simple test is enough, just create the bad config and call DefaultTenantManagerFactory

alanprot avatar Sep 08 '23 15:09 alanprot