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

do not import gcp-metadata rabbithole, if not needed #29

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

jeldeklint
Copy link
Contributor

@jeldeklint jeldeklint commented Dec 2, 2024

Cloud run imports are slow as is. Do not make it worse.
gcp-metadata pulls gaxios and json-bigint, always.
Should also be replaced with

const metadata = await fetch("http://metadata.google.internal/computeMetadata/v1/project/project-id", {
    headers: {
    "Metadata-Flavor": "Google",
  },
});

since node 18+ is required.

@jeldeklint
Copy link
Contributor Author

test-coverage seems drunk?

@jeldeklint jeldeklint requested review from wisko, MattiasOlla and kristofferjansson and removed request for wisko December 2, 2024 11:22
Copy link
Contributor

@assensamuelsson assensamuelsson left a comment

Choose a reason for hiding this comment

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

LGTM! Nice catch.

Is it really a good idea for us to force 100% code coverage?
When submitting PR's like this it is frustrating when not getting passed Github Actions for this reason.

We can track and report it somehow if we want to - but I vote for not having it as a requirement.

@wisko
Copy link
Contributor

wisko commented Dec 3, 2024

Regarding coverage: I think we can remove all ignore-coverage comments if we lower it to 90.

I think we should change gcp lib to optional dependency if we revert to importing this dynamically. Alternatively add it as an argument to the middleware, so that its the implementors responsibility to either set the env variable or pass an argument with the name. Thoughts?

@jeldeklint
Copy link
Contributor Author

I think we should change gcp lib to optional dependency if we revert to importing this dynamically. Alternatively add it as an argument to the middleware, so that its the implementors responsibility to either set the env variable or pass an argument with the name. Thoughts?

I think it will be less headaches to keep it in node_modules but maybe not using it. Removing an env can happen without rebuilding, or the same image being used in several places. Filesize is probably in KBs, it's the accesstime I want to avoid. (especially since it multiplies with depth)

@MattiasOlla
Copy link
Collaborator

I think we should change gcp lib to optional dependency if we revert to importing this dynamically. Alternatively add it as an argument to the middleware, so that its the implementors responsibility to either set the env variable or pass an argument with the name. Thoughts?

I think it will be less headaches to keep it in node_modules but maybe not using it. Removing an env can happen without rebuilding, or the same image being used in several places. Filesize is probably in KBs, it's the accesstime I want to avoid. (especially since it multiplies with depth)

I actually tried making it an optional dependency at first, but changed it due to optional dependencies being a pain to work with in node (I never thought I'd miss Python's dependency management).

I also absolutely agree that using fetch directly would be better, as long as we make sure that everything still works locally/when used outside of GCP, even when the env variable is not set.

@jeldeklint jeldeklint force-pushed the feat/async-import-gcp-metadata branch from c79c863 to ff29256 Compare December 3, 2024 12:44
@jeldeklint
Copy link
Contributor Author

I think we should change gcp lib to optional dependency if we revert to importing this dynamically. Alternatively add it as an argument to the middleware, so that its the implementors responsibility to either set the env variable or pass an argument with the name. Thoughts?

I think it will be less headaches to keep it in node_modules but maybe not using it. Removing an env can happen without rebuilding, or the same image being used in several places. Filesize is probably in KBs, it's the accesstime I want to avoid. (especially since it multiplies with depth)

I actually tried making it an optional dependency at first, but changed it due to optional dependencies being a pain to work with in node (I never thought I'd miss Python's dependency management).

I also absolutely agree that using fetch directly would be better, as long as we make sure that everything still works locally/when used outside of GCP, even when the env variable is not set.

Yes! Saw it! :D since gcp-metadata uses 169.254.169.254 or the internal host, it will fail outside of GCP anyway? We could just set the time out to like 5ms or such since the metadata api should respond very fast.

@MattiasOlla MattiasOlla merged commit ada406d into main Dec 10, 2024
1 check passed
@MattiasOlla MattiasOlla deleted the feat/async-import-gcp-metadata branch December 10, 2024 09:56
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.

4 participants