Skip to content

Commit

Permalink
Merge pull request #378 from michalvavrik/feature/make-app-more-real
Browse files Browse the repository at this point in the history
Make 'app-full-microprofile' project closer to what customers do and address engineering team feedback
  • Loading branch information
rsvoboda authored Jun 27, 2024
2 parents d002324 + c03c43b commit 9d2ea08
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 353 deletions.
12 changes: 2 additions & 10 deletions app-full-microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-jwt</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-jwt</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-metrics</artifactId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

import java.util.Random;

import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.annotation.Gauge;
import org.eclipse.microprofile.metrics.annotation.Metric;
import org.eclipse.microprofile.metrics.annotation.Timed;

import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/metric")
@ApplicationScoped //Required for @Gauge
public class MetricController {

@Inject
@Metric(name = "endpoint_counter")
private final MeterRegistry registry;

// https://quarkus.io/guides/cdi-reference#private-members
// - private Counter counter;
Counter counter;
public MetricController(MeterRegistry registry) {
this.registry = registry;
registry.gauge("counter_gauge", this, MetricController::getCustomerCount);
}

@Path("timed")
@Timed(name = "timed-request")
@Timed(value = "timed-request")
@GET
public String timedRequest() {
// Demo, not production style
Expand All @@ -43,12 +39,15 @@ public String timedRequest() {
@Path("increment")
@GET
public long doIncrement() {
counter.inc();
return counter.getCount();
getEndpointCounter().increment();
return (long) getEndpointCounter().count();
}

@Gauge(name = "counter_gauge", unit = MetricUnits.NONE)
long getCustomerCount() {
return counter.getCount();
return (long) getEndpointCounter().count();
}

private Counter getEndpointCounter() {
return registry.counter("endpoint_counter");
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.quarkus.serialization;

import com.example.quarkus.serialization.dto.ComplexDto;
import com.example.quarkus.serialization.dto.MyEnum;
import com.example.quarkus.serialization.dto.NestedClass;
import com.example.quarkus.serialization.dto.NestedInterface;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
* Tests DTO serialization as this is most likely done by majority of apps these days.
*/
@Produces(MediaType.APPLICATION_JSON)
@Path("serialization/json")
public class JsonResource {

@GET
@Path("complex-dto")
public ComplexDto complexDto() {
return new ComplexDto(MyEnum.ONE, new NestedClass(), NestedInterface.INSTANCE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.quarkus.serialization.dto;

public record ComplexDto(MyEnum myEnum, NestedClass nestedClass, NestedInterface nestedInterface) {
}
Loading

0 comments on commit 9d2ea08

Please sign in to comment.