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

Not able to load environment variables or connect to services via gradle+intellij #2785

Open
scottillogical opened this issue Sep 27, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@scottillogical
Copy link

scottillogical commented Sep 27, 2024

Bug Description

I recently got a new mac, setting it up I am not able to get intellij mirrord to load the environment variables correctly. This worked on my previous mac fine

Via CLI it works fine

mirrord exec -a scott1 --target=deployment/<APP> -- bash
$ env | grep MIRRORD_AGENT_NAMESPACE=scott1
MIRRORD_AGENT_NAMESPACE=scott1

But when I start up the java app in intellij, it does not load the environment variables from the target pod
Screenshot 2024-09-27 at 12 31 05 PM

Since in the past this has been due to SIP issue https://mirrord.dev/docs/faq/common-issues/ I copied my JDK into ~/java, but this did not ameliorate the issue

I also tried running sudo codesign --remove-signature ./<your-binary> but after that I could not boot the jdk without it exiting immediately afterwards. I tried other jdks no dice thus far

Steps to Reproduce

  1. Run java app in intellij
  2. Observe no environment variables

Backtrace

No response

Relevant Logs

No response

Your operating system and version

osx sonoma 14.7

Local process

$| file $JAVA_HOME/bin/java /Users/sschulthess/.jenv/versions/corretto64-1.8.0.422/bin/java: Mach-O 64-bit executable arm64

Local process version

$| java -version openjdk version "1.8.0_422" OpenJDK Runtime Environment Corretto-8.422.05.1 (build 1.8.0_422-b05) OpenJDK 64-Bit Server VM Corretto-8.422.05.1 (build 25.422-b05, mixed mode)

Additional Info

config file

{
    "target": {
        "path": {
            "deployment": "APP"
        },
        "namespace": "scott1"
    },
    "agent": {
        "namespace": "scott1"
    },
    "feature": {
        "network": {
            "incoming": "steal",
            "outgoing": {
                "filter": {
                    "local": [
                        "localhost:3000"
                    ]
                }
            }
        },
        "fs": "read"
    },
    "kube_context": "zc-carsharing-dev"
}
@scottillogical scottillogical added the bug Something isn't working label Sep 27, 2024
Copy link

linear bot commented Sep 27, 2024

@aviramha
Copy link
Member

Hi,
Environment variables can't be affected by SIP so it's probably not that.
Can you enable internal proxy logs by adding this to your mirrord.json:

{"internal_proxy": {"log_destination": "/tmp/internal_proxy.log", "log_level": "mirrord=trace"}}

then after running attaching the logs (after redacting sensitive information?

@aviramha aviramha self-assigned this Sep 27, 2024
@aviramha
Copy link
Member

User was able to reproduce it in a vanilla project launching "gradle run" - so perhaps the problem is with the gradle/intellij integration (not using IntelliJ's compilation/execution)

@scottillogical
Copy link
Author

I was looking into this more this morning and I was not able to get it working (still need to try on a different laptop but forgot that at home today)
@aviramha I did notice in my testing that my app was able to access the local filesystem. this was using the default setting which should b set to read. Does information help at all? My assumption was if mirrord is working with fs set to read:, my app will not be able to read from the local filesystem. Any tips or ideas why its not working with running with gradle+intellij?

@aviramha
Copy link
Member

Hey
setting fs to read means that most files would be from the remote, but not that local files wouldn't be available (it depends on our default filters)
We're planning to look into it soon.

@aviramha aviramha removed their assignment Sep 30, 2024
@scottillogical
Copy link
Author

Okay thanks for the update. I did confirm that its not just an environment variable issue, as when the environment variables are set manually, the app still can't connect to rabbitmq over mirrord

@scottillogical
Copy link
Author

Tried to get this working on a new mac, no dice. The problem is not just that it doesnt get env vars, even if it gets the env vars it cannot connect to rmq running in the namespace. But only when running via intellij gradle

@scottillogical
Copy link
Author

@scottillogical scottillogical changed the title Not able to load environment variables via intellij Not able to load environment variables or connect to services via gradle+intellij Oct 2, 2024
@scottillogical
Copy link
Author

Hey folks was playing around with this this morning. I was able to reproduce the issue on a sample gradle app by changing the run configuration

https://github.com/scottillogical/mirrord-gradle-bug

  1. In intellij, select FIle - New - Project from existing sources
  2. Select project directory
  3. update the mirrord settings to point at a deployment in your k8s cluster - mine is set to my namespace/app
  4. The broken run configuration should be preloaded - run that to observe only "hello world" and about 14 env vars
  5. Run the "works" configuration to observe that more env vars come through

The only difference between the two run configurations is the broken one runs jdk -cp test.main and the one that works runs jdk -cp test.

@aviramha
Copy link
Member

aviramha commented Oct 8, 2024

Ah that's extremely valuable, thank you @scottillogical
We've prioritized this - hope we'll have progress soon.

@Razz4780 Razz4780 self-assigned this Oct 8, 2024
@aviramha
Copy link
Member

aviramha commented Oct 8, 2024

I managed to reproduce thanks for the example!

@aviramha aviramha assigned aviramha and t4lz and unassigned Razz4780 and aviramha Oct 8, 2024
Copy link
Member

t4lz commented Oct 11, 2024

Documenting some early findings:
even with the "Works" configuration it only works sometimes for me.

It looks like sometimes the IDE creates a different type of configuration object without me (intentionally/knowingly) doing anything different.

When configuration has the dynamic type GradleRunConfiguration (which is ExternalSystemRunConfiguration), the application does not get the env from the cluster, even though that env is successfully fetched and is set to in the configuration. I don't know at what point it is lost.

image.png

When configuration is an ApplicationConfiguration the application does get the env as it should.

Pasted Graphic.png

debugging the plugin to find out why.

I'm getting the "good" type of configuration in one or two runs after starting the debug IDE, and after that only the "bad" type. I thought the difference has something to do with the env-cleanup in processTerminated, but I think if that were the case it would not sometimes work a second time.

@aviramha
Copy link
Member

Just a guess, but perhaps it's because isReattachDebugProcess = true? can you set it to false manually and see if it helps?

@aviramha
Copy link
Member

Tried it, nope

@aviramha
Copy link
Member

I would try to check where IntelliJ decides which configuratoin is to be used and see what's the logic there

@aviramha
Copy link
Member

This seems to be an IntelliJ issue on itself - if you add any environment variable to the run configuration it doesn't get to the debugged/ran process.
Created issue here https://youtrack.jetbrains.com/issue/IDEA-360874/Environment-variables-arent-set-in-Application-run-configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants