From 92367f45ff4b2b77c4f78a6c104ac51b6c08a5a4 Mon Sep 17 00:00:00 2001 From: Shahar Levy Date: Wed, 27 Nov 2024 15:02:12 +0200 Subject: [PATCH 1/5] spring2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3049e15..5837f54 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.taboola async-profiler-actuator-endpoint - 2.0.7 + 2.0.8 ${project.groupId}:${project.artifactId} Async Profiler Actuator Endpoint @@ -172,4 +172,4 @@ - \ No newline at end of file + From 607f5841c32ab43a1177c507eb62882c5af2db22 Mon Sep 17 00:00:00 2001 From: Shahar Levy Date: Wed, 27 Nov 2024 15:32:35 +0200 Subject: [PATCH 2/5] Change to spring2 API-kebab prop, @Endpoint, @Read/write instead of extend/override --- pom.xml | 11 +++++-- .../spring/AsyncProfilerEndpoint.java | 33 +++++++------------ .../spring/AsyncProfilerEndpointConfig.java | 9 +++-- .../spring/AsyncProfilerEndpointTest.java | 10 +----- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 5837f54..a547063 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.taboola async-profiler-actuator-endpoint - 2.0.8 + 3.0.0 ${project.groupId}:${project.artifactId} Async Profiler Actuator Endpoint @@ -48,8 +48,8 @@ 1.7.13 - 4.3.23.RELEASE - 1.5.20.RELEASE + 5.3.31 + 2.7.18 1.18.10 1.8 1.8 @@ -76,6 +76,11 @@ spring-web ${com.taboola.spring.version} + + org.springframework.boot + spring-boot-autoconfigure + ${com.taboola.spring.boot.version} + org.springframework.boot spring-boot-actuator diff --git a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java index bdf84ca..d704738 100644 --- a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java +++ b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java @@ -1,7 +1,8 @@ package com.taboola.async_profiler.spring; -import org.springframework.boot.actuate.endpoint.Endpoint; -import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -14,33 +15,18 @@ import com.taboola.async_profiler.api.facade.ProfileRequest; import com.taboola.async_profiler.api.facade.ProfileResult; -public class AsyncProfilerEndpoint implements MvcEndpoint { +@Endpoint(id = "async-profiler") +public class AsyncProfilerEndpoint { public static final String BINARY_PROFILE_ATTACHMENT_HEADER_VALUE = "attachment; filename=profile."; private final AsyncProfilerService asyncProfilerService; - private final boolean isSensitive; - public AsyncProfilerEndpoint(AsyncProfilerService asyncProfilerService, boolean isSensitive) { + public AsyncProfilerEndpoint(AsyncProfilerService asyncProfilerService) { this.asyncProfilerService = asyncProfilerService; - this.isSensitive = isSensitive; - } - - @Override - public String getPath() { - return "/async-profiler"; - } - - @Override - public boolean isSensitive() { - return isSensitive; - } - - @Override - public Class getEndpointType() { - return null; } + @WriteOperation @GetMapping(value = "/profile", produces = MediaType.ALL_VALUE) public ResponseEntity profile(ProfileRequest profileRequest) { ProfileResult profileResult = asyncProfilerService.profile(profileRequest); @@ -48,6 +34,7 @@ public ResponseEntity profile(ProfileRequest profileRequest) { return toResponseEntity(profileResult); } + @WriteOperation @GetMapping(value = "/stop", produces = MediaType.ALL_VALUE) public ResponseEntity stop() { ProfileResult profileResult = asyncProfilerService.stop(); @@ -55,6 +42,7 @@ public ResponseEntity stop() { return toResponseEntity(profileResult); } + @WriteOperation @GetMapping(value = "/start-continuous", produces = MediaType.ALL_VALUE) @ResponseBody public String startContinuous(ContinuousProfilingSnapshotRequest snapshotRequest) { @@ -63,6 +51,7 @@ public String startContinuous(ContinuousProfilingSnapshotRequest snapshotRequest return "Started continuous profiling with: " + snapshotRequest; } + @WriteOperation @GetMapping(value = "/stop-continuous", produces = MediaType.ALL_VALUE) @ResponseBody public String stopContinuous() { @@ -71,12 +60,14 @@ public String stopContinuous() { return "Stopped continuous profiling"; } + @ReadOperation @GetMapping(value = "/events") @ResponseBody public String getSupportedEvents() { return asyncProfilerService.getSupportedEvents(); } + @ReadOperation @GetMapping(value = "/version") @ResponseBody public String getVersion() { diff --git a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointConfig.java b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointConfig.java index eb65b2c..6d56273 100644 --- a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointConfig.java +++ b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointConfig.java @@ -3,7 +3,7 @@ import com.taboola.async_profiler.api.LabelsWrapper; import com.taboola.async_profiler.api.continuous.pyroscope.PyroscopeReporterConfig; import io.pyroscope.okhttp3.OkHttpClient; -import org.springframework.beans.factory.annotation.Value; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -30,7 +30,7 @@ public class AsyncProfilerEndpointConfig { @Bean - @ConfigurationProperties("com.taboola.asyncProfiler") + @ConfigurationProperties("com.taboola.async-profiler") public AsyncProfilerServiceConfigurations asyncProfilerServiceConfigurations() { return new AsyncProfilerServiceConfigurations(); } @@ -106,8 +106,7 @@ public AsyncProfilerService asyncProfilerService(AsyncProfilerFacade asyncProfil } @Bean - public AsyncProfilerEndpoint asyncProfilerEndpoint(AsyncProfilerService asyncProfilerService, - @Value("${com.taboola.asyncProfilerEndpoint.sensitive:false}") boolean isSensitive) { - return new AsyncProfilerEndpoint(asyncProfilerService, isSensitive); + public AsyncProfilerEndpoint asyncProfilerEndpoint(AsyncProfilerService asyncProfilerService) { + return new AsyncProfilerEndpoint(asyncProfilerService); } } diff --git a/src/test/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointTest.java b/src/test/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointTest.java index 86c034e..54e0f4f 100644 --- a/src/test/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointTest.java +++ b/src/test/java/com/taboola/async_profiler/spring/AsyncProfilerEndpointTest.java @@ -1,9 +1,7 @@ package com.taboola.async_profiler.spring; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -39,7 +37,7 @@ public class AsyncProfilerEndpointTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - asyncProfilerEndPoint = new AsyncProfilerEndpoint(asyncProfilerService, false); + asyncProfilerEndPoint = new AsyncProfilerEndpoint(asyncProfilerService); } @Test @@ -115,10 +113,4 @@ public void testGetVersion() { when(asyncProfilerService.getProfilerVersion()).thenReturn("1"); assertEquals("1", asyncProfilerEndPoint.getVersion()); } - - @Test - public void testIsSensitive() { - assertFalse(new AsyncProfilerEndpoint(asyncProfilerService, false).isSensitive()); - assertTrue(new AsyncProfilerEndpoint(asyncProfilerService, true).isSensitive()); - } } \ No newline at end of file From cb0925a951e6ab038314d251a9750f79dbc7aced Mon Sep 17 00:00:00 2001 From: Shahar Levy Date: Wed, 27 Nov 2024 16:01:01 +0200 Subject: [PATCH 3/5] add to EnableAutoConfiguration --- src/main/resources/META-INF/spring.factories | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/resources/META-INF/spring.factories diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..e61e843 --- /dev/null +++ b/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.taboola.async_profiler.spring.AsyncProfilerEndpointConfig \ No newline at end of file From 71d7d53d623d862f18d62f96074626c980e3502a Mon Sep 17 00:00:00 2001 From: Shahar Levy Date: Thu, 28 Nov 2024 15:13:17 +0200 Subject: [PATCH 4/5] revert to RestControllerEndpoint --- .../async_profiler/spring/AsyncProfilerEndpoint.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java index d704738..dbfcf4c 100644 --- a/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java +++ b/src/main/java/com/taboola/async_profiler/spring/AsyncProfilerEndpoint.java @@ -1,8 +1,6 @@ package com.taboola.async_profiler.spring; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; +import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -15,7 +13,7 @@ import com.taboola.async_profiler.api.facade.ProfileRequest; import com.taboola.async_profiler.api.facade.ProfileResult; -@Endpoint(id = "async-profiler") +@RestControllerEndpoint(id = "async-profiler") public class AsyncProfilerEndpoint { public static final String BINARY_PROFILE_ATTACHMENT_HEADER_VALUE = "attachment; filename=profile."; @@ -26,7 +24,6 @@ public AsyncProfilerEndpoint(AsyncProfilerService asyncProfilerService) { this.asyncProfilerService = asyncProfilerService; } - @WriteOperation @GetMapping(value = "/profile", produces = MediaType.ALL_VALUE) public ResponseEntity profile(ProfileRequest profileRequest) { ProfileResult profileResult = asyncProfilerService.profile(profileRequest); @@ -34,7 +31,6 @@ public ResponseEntity profile(ProfileRequest profileRequest) { return toResponseEntity(profileResult); } - @WriteOperation @GetMapping(value = "/stop", produces = MediaType.ALL_VALUE) public ResponseEntity stop() { ProfileResult profileResult = asyncProfilerService.stop(); @@ -42,7 +38,6 @@ public ResponseEntity stop() { return toResponseEntity(profileResult); } - @WriteOperation @GetMapping(value = "/start-continuous", produces = MediaType.ALL_VALUE) @ResponseBody public String startContinuous(ContinuousProfilingSnapshotRequest snapshotRequest) { @@ -51,7 +46,6 @@ public String startContinuous(ContinuousProfilingSnapshotRequest snapshotRequest return "Started continuous profiling with: " + snapshotRequest; } - @WriteOperation @GetMapping(value = "/stop-continuous", produces = MediaType.ALL_VALUE) @ResponseBody public String stopContinuous() { @@ -60,14 +54,12 @@ public String stopContinuous() { return "Stopped continuous profiling"; } - @ReadOperation @GetMapping(value = "/events") @ResponseBody public String getSupportedEvents() { return asyncProfilerService.getSupportedEvents(); } - @ReadOperation @GetMapping(value = "/version") @ResponseBody public String getVersion() { From 06aece5acb91eca1608033bed1ab8da1778266fe Mon Sep 17 00:00:00 2001 From: Shahar Levy Date: Sun, 1 Dec 2024 11:12:53 +0200 Subject: [PATCH 5/5] Removal of spring-framework dep, so it will use boot --- pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pom.xml b/pom.xml index a547063..f35ea60 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,6 @@ 1.7.13 - 5.3.31 2.7.18 1.18.10 1.8 @@ -66,16 +65,6 @@ agent 0.13.0 - - org.springframework - spring-context - ${com.taboola.spring.version} - - - org.springframework - spring-web - ${com.taboola.spring.version} - org.springframework.boot spring-boot-autoconfigure