Skip to content

Commit

Permalink
fix: resource detection for 2nd gen of Cloud Functions works incorrec…
Browse files Browse the repository at this point in the history
…tly (#1045)

* fix: resource detection for 2nd gen of Cloud Functions works incorrectly

* Add a test
  • Loading branch information
losalex committed Aug 25, 2022
1 parent 9b82109 commit dda1d0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit dda1d0a

Please sign in to comment.