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: resource detection for 2nd gen of Cloud Functions works incorrectly #1045

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ private static Resource detectResourceType() {
return Resource.Global;
}

if (getter.getEnv("FUNCTION_SIGNATURE_TYPE") != null
&& getter.getEnv("FUNCTION_TARGET") != null) {
return Resource.CloudFunction;
}
if (getter.getEnv("K_SERVICE") != null
&& getter.getEnv("K_REVISION") != null
&& getter.getEnv("K_CONFIGURATION") != null) {
Expand All @@ -179,10 +183,6 @@ private static Resource detectResourceType() {
&& getter.getEnv("GAE_VERSION") != null) {
return Resource.AppEngine;
}
if (getter.getEnv("FUNCTION_SIGNATURE_TYPE") != null
&& getter.getEnv("FUNCTION_TARGET") != null) {
return Resource.CloudFunction;
}
if (getter.getAttribute("instance/attributes/cluster-name") != null) {
return Resource.K8sContainer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public void testResourceTypeCloudFunction() {
expect(getterMock.getEnv("FUNCTION_SIGNATURE_TYPE")).andReturn(MOCKED_NON_EMPTY).once();
expect(getterMock.getEnv("FUNCTION_TARGET")).andReturn(MOCKED_NON_EMPTY).once();
expect(getterMock.getEnv("K_SERVICE")).andReturn(MockedFunctionName).anyTimes();
expect(getterMock.getEnv("K_REVISION")).andReturn(MockedFunctionName + ".1").anyTimes();
expect(getterMock.getEnv("K_CONFIGURATION"))
.andReturn(MockedFunctionName + "-config")
.anyTimes();
expect(getterMock.getEnv(anyString())).andReturn(null).anyTimes();
replay(getterMock);
// exercise
Expand Down