Skip to content

Commit 79e3137

Browse files
phipagAttyuttam
andauthored
feat(cold-start-detection): Suppress cold start detection for non ON-DEMAND invocations (#2329)
* fix: cold start only on on-demand invocation * fix: cold start only on on-demand invocation * fix: cold start only on on-demand invocation * mvn clean test is successful * reversed the sqllite changes * feat(cold-start-detection): Suppress cold start for non ON-DEMAND invocation (since there are no cold starts). --------- Co-authored-by: Attyuttam <[email protected]>
1 parent bb70c1b commit 79e3137

File tree

21 files changed

+36
-35
lines changed

21 files changed

+36
-35
lines changed

examples/powertools-examples-core-utilities/terraform/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

55
<name>Powertools for AWS Lambda (Java) - Examples - Core Utilities (logging, tracing, metrics) with Terraform</name>
@@ -101,7 +101,8 @@
101101
<configuration>
102102
<createDependencyReducedPom>false</createDependencyReducedPom>
103103
<transformers>
104-
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
104+
<transformer
105+
implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer" />
105106
</transformers>
106107
</configuration>
107108
</execution>
@@ -126,7 +127,6 @@
126127
<plugin>
127128
<groupId>org.apache.maven.plugins</groupId>
128129
<artifactId>maven-surefire-plugin</artifactId>
129-
<version>3.5.4</version>
130130
<configuration>
131131
<environmentVariables>
132132
<LAMBDA_TASK_ROOT>handler</LAMBDA_TASK_ROOT>

examples/powertools-examples-parameters/sam-graalvm/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>software.amazon.lambda.examples</groupId>
55
<version>2.8.0</version>
@@ -98,8 +98,6 @@
9898
<plugin>
9999
<groupId>org.apache.maven.plugins</groupId>
100100
<artifactId>maven-surefire-plugin</artifactId>
101-
<!-- JUnit 5 requires Surefire version 3.1.0 or higher -->
102-
<version>3.5.4</version>
103101
</plugin>
104102
<plugin>
105103
<groupId>dev.aspectj</groupId>
@@ -144,7 +142,8 @@
144142
<configuration>
145143
<createDependencyReducedPom>false</createDependencyReducedPom>
146144
<transformers>
147-
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
145+
<transformer
146+
implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer" />
148147
</transformers>
149148
</configuration>
150149
</execution>

examples/powertools-examples-parameters/sam/pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>software.amazon.lambda.examples</groupId>
55
<version>2.8.0</version>
@@ -72,8 +72,6 @@
7272
<plugin>
7373
<groupId>org.apache.maven.plugins</groupId>
7474
<artifactId>maven-surefire-plugin</artifactId>
75-
<!-- JUnit 5 requires Surefire version 3.1.0 or higher -->
76-
<version>3.5.4</version>
7775
</plugin>
7876
<plugin>
7977
<groupId>dev.aspectj</groupId>

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
9696
<aspectj.version>1.9.7</aspectj.version>
9797
<aspectj-maven-plugin.version>1.13.1</aspectj-maven-plugin.version>
98-
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
9998
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
10099
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
101100
<maven-javadoc-plugin.version>3.12.0</maven-javadoc-plugin.version>
@@ -625,7 +624,6 @@
625624
<plugin>
626625
<groupId>org.apache.maven.plugins</groupId>
627626
<artifactId>maven-surefire-plugin</artifactId>
628-
<version>3.5.4</version>
629627
<configuration>
630628
<argLine>
631629
@{argLine}

powertools-common/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
<plugin>
107107
<groupId>org.apache.maven.plugins</groupId>
108108
<artifactId>maven-surefire-plugin</artifactId>
109-
<version>3.5.4</version>
110109
<configuration>
111110
<argLine>
112111
-Dorg.graalvm.nativeimage.imagecode=agent

powertools-common/src/main/java/software/amazon/lambda/powertools/common/internal/LambdaConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ private LambdaConstants() {
2828
public static final String ROOT_EQUALS = "Root=";
2929
public static final String POWERTOOLS_SERVICE_NAME = "POWERTOOLS_SERVICE_NAME";
3030
public static final String SERVICE_UNDEFINED = "service_undefined";
31+
public static final String AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE";
32+
public static final String ON_DEMAND_INVOCATION_TYPE = "on-demand";
3133
}

powertools-common/src/main/java/software/amazon/lambda/powertools/common/internal/LambdaHandlerProcessor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ protected static void resetServiceName() {
9393
}
9494

9595
public static boolean isColdStart() {
96-
return isColdStart == null;
96+
if (isColdStart != null) {
97+
return isColdStart;
98+
}
99+
100+
String initType = System.getenv(LambdaConstants.AWS_LAMBDA_INITIALIZATION_TYPE);
101+
isColdStart = LambdaConstants.ON_DEMAND_INVOCATION_TYPE.equals(initType);
102+
103+
return isColdStart;
97104
}
98105

99106
public static void coldStartDone() {

powertools-common/src/test/java/software/amazon/lambda/powertools/common/internal/LambdaHandlerProcessorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ void extractContext_notKnownHandler() {
216216
}
217217

218218
@Test
219+
@SetEnvironmentVariable(key = LambdaConstants.AWS_LAMBDA_INITIALIZATION_TYPE, value = LambdaConstants.ON_DEMAND_INVOCATION_TYPE)
219220
void isColdStart() {
220221
boolean isColdStart = LambdaHandlerProcessor.isColdStart();
221222

powertools-e2e-tests/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214
<plugin>
215215
<groupId>org.apache.maven.plugins</groupId>
216216
<artifactId>maven-failsafe-plugin</artifactId>
217-
<version>3.5.4</version>
218217
<executions>
219218
<execution>
220219
<goals>
@@ -241,7 +240,6 @@
241240
<plugin>
242241
<groupId>org.apache.maven.plugins</groupId>
243242
<artifactId>maven-failsafe-plugin</artifactId>
244-
<version>3.5.4</version>
245243
<executions>
246244
<execution>
247245
<goals>

powertools-logging/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
<plugin>
124124
<groupId>org.apache.maven.plugins</groupId>
125125
<artifactId>maven-surefire-plugin</artifactId>
126-
<version>3.5.4</version>
127126
<configuration>
128127
<argLine>
129128
-Dorg.graalvm.nativeimage.imagecode=agent
@@ -182,11 +181,11 @@
182181
<plugin>
183182
<groupId>org.apache.maven.plugins</groupId>
184183
<artifactId>maven-surefire-plugin</artifactId>
185-
<version>3.5.4</version>
186184
<configuration>
187185
<environmentVariables>
188186
<AWS_LAMBDA_LOG_FORMAT>JSON</AWS_LAMBDA_LOG_FORMAT>
189187
<POWERTOOLS_SERVICE_NAME>testService</POWERTOOLS_SERVICE_NAME>
188+
<AWS_LAMBDA_INITIALIZATION_TYPE>on-demand</AWS_LAMBDA_INITIALIZATION_TYPE>
190189
</environmentVariables>
191190
</configuration>
192191
</plugin>

0 commit comments

Comments
 (0)