Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai): (FTI-6403) Fixed error with Azure path override formatting #14051

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tysoekong
Copy link
Contributor

Summary

There was a bug found, where the Azure provider stopped parsing 'custom upstream path' overrides since Kong 3.9.0.

Every request would 404 due to incorrect parsing.

I've added a parser / config options test to prevent this from happening again!

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md

Issue reference

FTI-6403
AG-191

@tysoekong tysoekong force-pushed the fix/ai_preserve_route_type branch from 9c0c579 to bedbcc7 Compare December 24, 2024 20:52
ai_shared.override_upstream_url(parsed_url, conf)

-- if the path is read from a URL capture, 3re that it is valid
parsed_url.path = string_gsub(parsed_url.path, "^/*", "/")
kong.log.warn("JJ: ", parsed_url.path)
Copy link
Member

Choose a reason for hiding this comment

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

let's remove the debug line.

@@ -118,10 +118,18 @@ function _M.configure_request(conf)
parsed_url = socket_url.parse(url)
end

-- if the path is read from a URL capture, ensure that it is valid
parsed_url.path = string_gsub(parsed_url.path, "^/*", "/")
Copy link
Member

Choose a reason for hiding this comment

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

for what case? it seems not possible to get a dirty URL path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added because it was reported that it broke when you set like this:

config:
  model:
    options:
      upstream_url: http://localhost:8080

for example.

I don't want to remove this, it was to fix a very specific issue for someone.

-- Azure-specific - prepend the deployment instance path to the
-- user-override path.
if conf.model.options and conf.model.options.upstream_path then
conf.model.options.upstream_path = parsed_url.path
Copy link
Member

Choose a reason for hiding this comment

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

The dynamic change conf in runtime is wired for me. we need to rebuilt route in here I think

  if conf.model.options.upstream_url then
    parsed_url = socket_url.parse(conf.model.options.upstream_url)
  else
    -- azure has non-standard URL format
    local url = fmt(
      "%s%s",
      ai_shared.upstream_url_format[DRIVER_NAME]:format(conf.model.options.azure_instance, conf.model.options.azure_deployment_id),
          conf.model.options
      and conf.model.options.upstream_path
      or ai_shared.operation_map[DRIVER_NAME][conf.route_type]
      and ai_shared.operation_map[DRIVER_NAME][conf.route_type].path
      or "/"
    )
    parsed_url = socket_url.parse(url)
  end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oowl I don't understand the proposal :( can you just push the change in and run the CI?

My tests absolutely 100% covers the client's issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants