Skip to content

Commit

Permalink
ch16 ingredient add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrace-git committed Jan 15, 2023
1 parent ddc478d commit d791917
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.ingredientservice;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -18,10 +19,12 @@
public class IngredientController {

private IngredientRepository repo;
private final MeterRegistry meterRegistry;

@Autowired
public IngredientController(IngredientRepository repo) {
public IngredientController(IngredientRepository repo, MeterRegistry meterRegistry) {
this.repo = repo;
this.meterRegistry = meterRegistry;
}

@GetMapping
Expand All @@ -44,6 +47,7 @@ private Iterable<Ingredient> getDefaultIngredients() throws InterruptedException

@GetMapping("/{id}")
public Optional<Ingredient> byId(@PathVariable String id) {
meterRegistry.counter("tacocloud", "ingredient", id).increment();
return repo.findById(id);
}

Expand Down

0 comments on commit d791917

Please sign in to comment.