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

Mint removes Python modules if modules are loaded dynamically #752

Open
jkempf42 opened this issue Feb 13, 2025 · 11 comments
Open

Mint removes Python modules if modules are loaded dynamically #752

jkempf42 opened this issue Feb 13, 2025 · 11 comments

Comments

@jkempf42
Copy link

If you include code like this:

                module = importlib.import_module(module_name)

which dynamically loads the module. I suspect mint is currently just following the imports down from the top level function, which won't catch dynamically loaded modules.

@kcq
Copy link
Member

kcq commented Feb 13, 2025

@jkempf42 Is this a server app or a CLI app? This python app is a good candidate for additional probe parameters. The goal of those probes would be to trigger the flow where that module is loaded dynamically. There are several probe types. The HTTP/network probes (configured using the --http-probe-* flags) interact with the server applications. The exec probes (configured using the --exec and --exec-file flags) allow you to run extra commands in the ephemeral container when the application is running.

@jkempf42
Copy link
Author

jkempf42 commented Feb 13, 2025 via email

@kcq
Copy link
Member

kcq commented Feb 15, 2025

@jkempf42 this sounds promising! Is there a simple example of for a containerized Azure Function you'd recommend for a repro? Maybe an open source project or just sample code?

@jkempf42
Copy link
Author

jkempf42 commented Feb 15, 2025 via email

@kcq
Copy link
Member

kcq commented Feb 16, 2025

@jkempf42 thank you! looking forward to exploring those and confirming the flags to use with those containers.

@jkempf42
Copy link
Author

jkempf42 commented Feb 16, 2025 via email

@kcq
Copy link
Member

kcq commented Feb 16, 2025

@jkempf42 try this command: mint build --expose 80 --http-probe-cmd '/api/mint_bug_example?name=Darth_Vader' --http-probe-cmd '/api/mint_bug_example?name=Chauncy_Laubach' mint-bug:latest

@jkempf42
Copy link
Author

jkempf42 commented Feb 16, 2025 via email

@kcq
Copy link
Member

kcq commented Feb 16, 2025

@jkempf42 the --http-probe-cmd-file flag gives you more control over the HTTP requests including the headers. Here's a sample command definition file for that flag has a custom request header defined:

{
  "commands":
  [
   {
     "protocol": "http",
     "method": "POST",
     "resource": "/submit2",
     "body": "key=value"
   },
   {
     "protocol": "http",
     "method": "POST",
     "resource": "/submit3",
     "body_file": "mydata.json",
     "headers": ["Content-Type: application/json"]
   }
  ]
}

You don't need to go through all possible value, but you do need to be aware of special cases. Usually there are only a few cases like that.

Good to note that with servers/services that have swagger/OpenAPI API specs you can point to those (with the --http-probe-apispec or --http-probe-apispec-file flags) and that reduces the number of custom HTTP probe commands you need to specify explicitly.

There's also an automated way to generate the necessary probes, but it goes beyond the capabilities of the toolkit because additional context is needed. This autonomous probing capability is available in the AppDroid service we have (available in closed beta at this point in time).

@jkempf42
Copy link
Author

jkempf42 commented Feb 16, 2025 via email

@jkempf42
Copy link
Author

jkempf42 commented Feb 17, 2025 via email

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

No branches or pull requests

2 participants