Skip to content

feat(slack): derive chat.update URL from configured api_url base#5225

Draft
santiagofn wants to merge 2 commits into
prometheus:mainfrom
santiagofn:refactor/slack-extract-apiurl-pkg
Draft

feat(slack): derive chat.update URL from configured api_url base#5225
santiagofn wants to merge 2 commits into
prometheus:mainfrom
santiagofn:refactor/slack-extract-apiurl-pkg

Conversation

@santiagofn
Copy link
Copy Markdown
Contributor

@santiagofn santiagofn commented May 6, 2026

Part 3 of a series implementing threaded message support for the Slack notifier. Full picture: #5150. Depends on #5239.

Summary

Moves the Slack notifier's URL resolution into a new internal package notify/slack/internal/apiurl, and routes both the initial chat.postMessage request and the chat.update request (used by update_message: true) through the same configured api_url / api_url_file base.

Behavior change

Previously the chat.update endpoint was hardcoded to https://slack.com/api/chat.update regardless of api_url. With this PR, the same base used for chat.postMessage is reused for chat.update.

  • Standard configurations (api_url unset or pointing at https://slack.com/api/chat.postMessage) are unaffected: the generated URL is byte-identical to today.
  • Deployments that point api_url at a Slack-API-compatible proxy or forwarder (e.g. https://my-proxy.example.com/slack/api/chat.postMessage) will now have their chat.update requests routed to the same host (https://my-proxy.example.com/slack/api/chat.update) instead of being forced back onto slack.com. For these users this is the more correct behavior, but it is a behavior change and is recorded as a `[CHANGE]` in the CHANGELOG.

Implementation

  • New apiurl.Resolver captures api_url / api_url_file at notifier construction. URLForMethod("") returns the configured base URL (initial post); URLForMethod("chat.update") derives the URL by replacing the last path segment of the base, so any base path (e.g. /slack/api/chat.postMessage) is honored.
  • api_url_file is read on every call, matching previous behavior so that file rotations apply to the next notification without restarting Alertmanager.
  • notify/slack/slack.go now delegates both URL constructions to the resolver. The previous TestGettingSlackURLFromFile and TestTrimmingSlackURLFromFile are replaced by the resolver-level coverage in apiurl_test.go.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 332b0527-7696-4546-949c-ebd8b18f68ae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@SoloJacobs SoloJacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was largely AI-generated. We'd ask that contributions be reviewed and understood by the author before submitting, including making sure the commit message accurately describes what the code actually does. The message here says "refactor" but the change alters behavior. Happy to look at it again once it's been properly reviewed on your end.

@santiagofn
Copy link
Copy Markdown
Contributor Author

It looks like this was largely AI-generated. We'd ask that contributions be reviewed and understood by the author before submitting, including making sure the commit message accurately describes what the code actually does. The message here says "refactor" but the change alters behavior. Happy to look at it again once it's been properly reviewed on your end.

hi, @SoloJacobs , sorry for the delay. one comment before all: this is still a draft, that's why i didn't share it on slack. regarding the comments, i not only reviewed but wrote code, the PR was not solely generated by AI. i chose a "refactor" label because the current behaviour was not change (the same URLs are generated in the current flow). what the PR did add was the ability of creating URLs for other methods... but they're not in use nowadays. anyways, it might be worth using a "feature" if you believe that potential use warrants it.

@SoloJacobs
Copy link
Copy Markdown
Contributor

Thanks for the context. To be more precise though: The commit description says "move", which implies pure relocation.

  • The chat.update URL changed from hardcoded (https://slack.com/api/chat.update) to derived from the configured base URL, which is a behavioral change for anyone using a custom api_url.
  • The URL logic went from ~12 lines to 108. If this is a "move", then we is all the extra logic necessary?

So, the "refactor" part is not really the issue, you could leave it. Although, feat does seem a bit more accurate to me, since you introduce a new capability. But that is secondary

@santiagofn santiagofn force-pushed the refactor/slack-extract-apiurl-pkg branch 3 times, most recently from f912d94 to 0649d19 Compare May 14, 2026 17:43
@santiagofn santiagofn changed the title refactor: move slack url creation to its own package feat(slack): derive chat.update URL from configured api_url base May 14, 2026
@santiagofn santiagofn force-pushed the refactor/slack-extract-apiurl-pkg branch 3 times, most recently from 42ea34e to bd70a71 Compare May 19, 2026 17:39
santiagofn and others added 2 commits May 19, 2026 14:44
Moves SlackConfig (and the related SlackAction, SlackConfirmationField,
SlackField types plus DefaultSlackConfig) from config/notifiers.go into
a new notify/slack/config.go, following the same pattern used recently
for the mattermost, jira, and incidentio notifiers.

While moving them, the Slack prefix is dropped per the package-naming
guidance in https://go.dev/blog/package-names ("Avoid repetition"):
SlackConfig -> Config, DefaultSlackConfig -> DefaultConfig, SlackAction
-> Action, SlackConfirmationField -> ConfirmationField, SlackField ->
Field. External callers now refer to slack.Config etc., reading better
than the previous slack.SlackConfig stutter.

The Slack-specific unmarshal tests are moved alongside them into
notify/slack/config_test.go. config.Receiver now refers to
*slack.Config, and notify/slack no longer needs to import the top-level
config package.

No behavioral changes.

Signed-off-by: Santiago Fernández Núñez <santiago.nunez@nubank.com.br>
Co-authored-by: Cursor <cursoragent@cursor.com>
Previously the Slack notifier hardcoded the chat.update endpoint to
"https://slack.com/api/chat.update" regardless of the configured
api_url. Deployments pointing api_url at a Slack-compatible proxy or
forwarder were therefore forced back onto slack.com for update calls,
which is the wrong host for proxy users.

Move the URL handling into a new internal/apiurl package, and route
chat.update (and any future Slack Web API method) through the same
api_url / api_url_file base as the initial chat.postMessage call.
Standard configurations are unaffected; the generated URL is byte
identical.

The Resolver also reads api_url_file on every call, matching previous
behaviour so that file rotations apply to the next notification without
restarting Alertmanager.

Signed-off-by: Santiago Fernández Núñez <santiago.nunez@nubank.com.br>
Co-authored-by: Cursor <cursoragent@cursor.com>
@santiagofn santiagofn force-pushed the refactor/slack-extract-apiurl-pkg branch from bd70a71 to dd56508 Compare May 19, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants