-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal sample with Hazelcast and native-image
- Loading branch information
1 parent
1309cf9
commit 71b4f87
Showing
5 changed files
with
28 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
hazelcast: | ||
container_name: hazelcast | ||
image: hazelcast/hazelcast | ||
extra_hosts: [ 'host.docker.internal:host-gateway' ] | ||
restart: always | ||
ports: | ||
- 5701:5701 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package org.example.ecoli; | ||
|
||
import com.hazelcast.client.config.ClientConfig; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@EnableCaching | ||
@SpringBootApplication | ||
public class EcoliApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(EcoliApplication.class, args); | ||
} | ||
|
||
@Bean | ||
ClientConfig hazelcastClientConfig() { | ||
return new ClientConfig(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,17 @@ | ||
package org.example.ecoli; | ||
|
||
import java.util.List; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.TraceContext; | ||
import io.micrometer.tracing.Tracer; | ||
|
||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class EcoliRestController { | ||
private final MeterRegistry meterRegistry; | ||
private final Tracer tracer; | ||
|
||
public EcoliRestController(MeterRegistry meterRegistry, Tracer tracer) { | ||
this.meterRegistry = meterRegistry; | ||
this.tracer = tracer; | ||
} | ||
|
||
@Cacheable("echo") | ||
@GetMapping("/echo/{message}") | ||
public EchoResponse echo(@PathVariable String message) { | ||
return new EchoResponse(message); | ||
public String echo(@PathVariable String message) { | ||
return message; | ||
} | ||
|
||
@GetMapping("/throughput") | ||
public ThroughputResponse throughput() { | ||
List<String> counters = meterRegistry.find("http.server.requests").timers().stream() | ||
.map(timer -> String.format("%s%s %d", timer.getId().getName(), timer.getId().getTags(), timer.count())) | ||
.toList(); | ||
return new ThroughputResponse(counters); | ||
} | ||
|
||
@GetMapping("/span") | ||
public SpanResponse span() { | ||
return new SpanResponse(tracer.currentSpan()); | ||
} | ||
|
||
public record EchoResponse(String message) { | ||
} | ||
|
||
public record ThroughputResponse(List<String> counters) { | ||
} | ||
|
||
public static class SpanResponse { | ||
private final String traceId; | ||
private final String spanId; | ||
private final String parentSpanId; | ||
|
||
SpanResponse(Span span) { | ||
if (span != null) { | ||
TraceContext traceContext = span.context(); | ||
this.traceId = traceContext.traceId(); | ||
this.spanId = traceContext.spanId(); | ||
this.parentSpanId = span.context().parentId(); | ||
} | ||
else { | ||
this.traceId = null; | ||
this.spanId = null; | ||
this.parentSpanId = null; | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public String getTraceId() { | ||
return this.traceId; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public String getSpanId() { | ||
return this.spanId; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public String getParentSpanId() { | ||
return this.parentSpanId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
spring.application.name=ecoli | ||
|
||
management.endpoints.web.exposure.include=* | ||
management.tracing.sampling.probability=1.0 | ||
management.metrics.distribution.percentiles-histogram.http.server.requests=true | ||
|
||
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG |