У меня есть следующий простой код: < /p>
Код: Выделить всё
@GetMapping("/question")
Mono question(@RequestParam(value = "id", required = true) int id) {
return Mono.just(id)
.map(oneId -> doSomeLenghtyInMemoryNonBlockingOperation(oneId))
;
}
private String doSomeLenghtyInMemoryNonBlockingOperation(int oneId) {
//This is the business code I would like to observe, hope to compute the histogram for this.
//the business logic runs some tasks which takes (variable amount) of time
return ...;
}
< /code>
Часть, которую я хотел бы наблюдать, является методом в функции карты. Иногда он работает быстро, иногда медленно работает и т. Д. < /p>
Поскольку это важная часть бизнес -логики, я бы хотел, чтобы она наблюдалась. < /P>
Выпуск 1: В не реактивном мире что -то вроде добавления @timed (value = "some_values", Histogram = true Выпуск 2: этот (хороший) документ https://docs.micromert.io/micrometer/re ... tiles.html показывает, как построить таймер с гистограммами и процентилами, но нет Примеры для реактивных приложений.
Выпуск 3: Это (также хорошо) документ https://docs.micrometer.io/micrometer/r ... ctor_3_5_3 показывает примеры Reactive of Reactive of Reactive of Reactive of Reactive of Reactive of Reactive of Reactive Библиотеки с .tap (micrometer.observation (наблюдение)) < /code>, но не объясняет, как комбинироваться с процентилями /гистограммами < /p>
Я пытался: < /p>
@RestController
class QuestionController {
MeterRegistry meterRegistry;
Timer timer;
public QuestionController(ObservationRegistry observationRegistry, MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
// what to do with this timer in a reactive world?
this.timer = Timer.builder("percentile.timer")
.publishPercentiles(0.5, 0.95)
.publishPercentileHistogram()
.serviceLevelObjectives(Duration.ofMillis(100))
.minimumExpectedValue(Duration.ofMillis(1))
.maximumExpectedValue(Duration.ofSeconds(10))
.register(meterRegistry);
}
@GetMapping("/question")
Mono question(@RequestParam(value = "id", required = true) int id) {
return Mono.just(id)
.map(oneId -> doSomeLenghtyInMemoryNonBlockingOperation(oneId))
;
}
private String doSomeLenghtyInMemoryNonBlockingOperation(int oneId) {
//This is the business code I would like to observe, hope to compute the histogram for this.
//the business logic runs some tasks which takes a certain (variable amount) of time
return ...;
}
}
< /code>
, а также: < /p>
@RestController
class QuestionController {
ObservationRegistry observationRegistry;
public QuestionController(ObservationRegistry observationRegistry, MeterRegistry meterRegistry) {
this.observationRegistry = observationRegistry;
}
@GetMapping("/question")
Mono question(@RequestParam(value = "id", required = true) int id) {
return Mono.just(id)
.map(oneId -> doSomeLenghtyInMemoryNonBlockingOperation(oneId))
// is this the correct use of tap? Should it be before or after the previous line?
// how to get the histogram from this?
.name("shouldNameAndTapBeBeforeOrAfterTheThingToObserve")
.tap(Micrometer.observation(observationRegistry))
;
}
private String doSomeLenghtyInMemoryNonBlockingOperation(int oneId) {
//This is the business code I would like to observe hope to compute the histogram for this.
//the business logic runs some tasks which takes a certain (variable amount) of time
return "";
}
}
< /code>
Ни один из них не генерирует гистограммы (или процентили) < /p>
Вопрос: < /p>
Как генерировать гистограмму для пружины Webflux / реактивные приложения? < / P>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -operation