Skip to content

Commit

Permalink
Replace the MeterRegistery by the @timed Micrometer annotation #120
Browse files Browse the repository at this point in the history
  • Loading branch information
arey committed Mar 10, 2019
1 parent 759c7a8 commit aa688d5
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 48 deletions.
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
<sleuth.version>2.0.0.RC2</sleuth.version>
<micrometer.version>1.0.5</micrometer.version>

<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>

Expand Down Expand Up @@ -79,18 +78,6 @@
<scope>test</scope>
</dependency>

<!-- Micrometer core dependency -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version>
</dependency>
<!-- Micrometer Prometheus registry -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 0 additions & 4 deletions spring-petclinic-api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions spring-petclinic-customers-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.samples.petclinic.customers.web;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand All @@ -36,20 +36,19 @@
*/
@RequestMapping("/owners")
@RestController
@Timed("petclinic.owner")
@RequiredArgsConstructor
@Slf4j
class OwnerResource {

private final OwnerRepository ownerRepository;
private final MeterRegistry registry;

/**
* Create Owner
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createOwner(@Valid @RequestBody Owner owner) {
registry.counter("create.owner").increment();
ownerRepository.save(owner);
}

Expand Down Expand Up @@ -84,7 +83,6 @@ public Owner updateOwner(@PathVariable("ownerId") int ownerId, @Valid @RequestBo
ownerModel.setAddress(ownerRequest.getAddress());
ownerModel.setTelephone(ownerRequest.getTelephone());
log.info("Saving owner {}", ownerModel);
registry.counter("update.owner").increment();
return ownerRepository.save(ownerModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.samples.petclinic.customers.web;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand All @@ -32,13 +32,13 @@
* @author Maciej Szarlinski
*/
@RestController
@Timed("petclinic.pet")
@RequiredArgsConstructor
@Slf4j
class PetResource {

private final PetRepository petRepository;
private final OwnerRepository ownerRepository;
private final MeterRegistry registry;


@GetMapping("/petTypes")
Expand All @@ -57,7 +57,6 @@ public void processCreationForm(
Owner owner = optionalOwner.orElseThrow(() -> new ResourceNotFoundException("Owner "+ownerId+" not found"));
owner.addPet(pet);

registry.counter("create.pet").increment();
save(pet, petRequest);
}

Expand All @@ -66,7 +65,6 @@ public void processCreationForm(
public void processUpdateForm(@RequestBody PetRequest petRequest) {
int petId = petRequest.getId();
Pet pet = findPetById(petId);
registry.counter("update.pet").increment();
save(pet, petRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Optional;

import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -42,9 +41,6 @@ class PetResourceTest {
@MockBean
OwnerRepository ownerRepository;

@MockBean
MeterRegistry registry;

@Test
void shouldGetAPetInJSonFormat() throws Exception {

Expand Down
4 changes: 0 additions & 4 deletions spring-petclinic-vets-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions spring-petclinic-visits-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;
import javax.validation.Valid;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -43,10 +43,10 @@
@RestController
@RequiredArgsConstructor
@Slf4j
@Timed("petclinic.visit")
class VisitResource {

private final VisitRepository visitRepository;
private final MeterRegistry registry;

@PostMapping("owners/*/pets/{petId}/visits")
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand All @@ -56,7 +56,6 @@ void create(

visit.setPetId(petId);
log.info("Saving visit {}", visit);
registry.counter("create.visit").increment();
visitRepository.save(visit);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.springframework.samples.petclinic.visits.web;

import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -30,9 +29,6 @@ class VisitResourceTest {
@MockBean
VisitRepository visitRepository;

@MockBean
MeterRegistry registry;

@Test
void shouldFetchVisits() throws Exception {
given(visitRepository.findByPetIdIn(asList(111, 222)))
Expand Down

0 comments on commit aa688d5

Please sign in to comment.