Feedback edits (#7)

* Feedback edits

* Revert script changes

* Bump service-parent-pom

* Metric enum added

* Replace metric with label

* Fix metric

* Fix metrics
This commit is contained in:
Egor Cherniak 2022-06-01 14:30:59 +03:00 committed by GitHub
parent 1d169a7577
commit c3238fd264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 103 additions and 69 deletions

View File

@ -38,14 +38,13 @@ Beholder умеет работать c простым selenium-hub и с [lambda
#### Метрики
| Название | Лейблы | Описание |
|--------------------------------------------------|-----------------|------------------------------------------------------------------------------|
| beholder_form_loading_requests_total | browser, region | счетчик запросов на загрузку формы |
| beholder_form_loading_failed_total | browser, region | счетчик неудачных загрузок формы |
| beholder_form_dom_complete_duration_millis | browser, region | время от момента отправки запроса до полной загрузки формы в миллисекундах |
| beholder_form_waiting_response_duration_millis | browser, region | время от момента отправки запроса до начала получения ответа в миллисекундах |
| beholder_form_receiving_response_duration_millis | browser, region | время между получением первым и последним байтом информации в миллисекундах |
| beholder_form_resource_loading_duration_millis | browser, region | время, затраченное на загрузку ресурса (включая блокировки, ожидание и т.д) |
| Название | Лейблы | Описание |
|--------------------------------------------------|----------------------------|------------------------------------------------------------------------------|
| beholder_form_loading_requests_total | browser, region, result | счетчик запросов на загрузку формы |
| beholder_form_dom_complete_duration_millis | browser, region | время от момента отправки запроса до полной загрузки формы в миллисекундах |
| beholder_form_waiting_response_duration_millis | browser, region | время от момента отправки запроса до начала получения ответа в миллисекундах |
| beholder_form_receiving_response_duration_millis | browser, region | время между получением первым и последним байтом информации в миллисекундах |
| beholder_form_resource_loading_duration_millis | browser, region, resource | время, затраченное на загрузку ресурса (включая блокировки, ожидание и т.д) |
## Тестирование

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>1.0.16</version>
<version>1.0.17</version>
</parent>
<artifactId>beholder</artifactId>

View File

@ -0,0 +1,46 @@
package dev.vality.beholder.model;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public enum Metric {
RESOURCE_LOADING_DURATION(
"beholder_form_resource_loading_duration",
"Resources uploading time",
MetricUnit.MILLIS.getUnit()
),
WAITING_RESPONSE_DURATION(
"beholder_form_waiting_response_duration",
"Time between sending request and first received byte of data",
MetricUnit.MILLIS.getUnit()
),
RECEIVING_RESPONSE_DURATION(
"beholder_form_receiving_response_duration",
"Time between receiving first and last byte of data",
MetricUnit.MILLIS.getUnit()
),
DOM_COMPLETE_DURATION(
"beholder_form_dom_complete_duration",
"Time between sending request and fully rendered DOM",
MetricUnit.MILLIS.getUnit()
),
FORM_LOADING_REQUESTS(
"beholder_form_loading_requests",
"Total requests for form upload",
MetricUnit.TOTAL.getUnit()
);
@Getter
private final String name;
@Getter
private final String description;
@Getter
private final String unit;
}

View File

@ -0,0 +1,15 @@
package dev.vality.beholder.model;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum MetricUnit {
TOTAL("total"),
MILLIS("millis");
@Getter
private final String unit;
}

View File

@ -42,6 +42,5 @@ public class BeholderService {
}
metricsService.updateMetrics(responses);
log.info("Finished processing requests from {} regions", regions);
}
}

View File

@ -1,14 +1,13 @@
package dev.vality.beholder.service;
import dev.vality.beholder.model.FormDataResponse;
import dev.vality.beholder.model.Metric;
import dev.vality.beholder.util.MetricUtil;
import io.micrometer.core.instrument.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import static java.util.stream.Collectors.toList;
@ -22,38 +21,31 @@ public class MetricsService {
private final MultiGauge formDataWaitingDurationGauges;
private final MultiGauge formDataReceivingDuration;
private final MultiGauge formDomCompleteDuration;
private final Map<String, Counter> formLoadingCounters;
private final Map<String, Counter> formLoadingFailedCounters;
public MetricsService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
this.resourcesLoadingTimings = MultiGauge.builder("beholder_form_resource_loading_duration")
.description("Resources uploading time")
.baseUnit("millis")
this.resourcesLoadingTimings = MultiGauge.builder(Metric.RESOURCE_LOADING_DURATION.getName())
.description(Metric.RESOURCE_LOADING_DURATION.getDescription())
.baseUnit(Metric.RESOURCE_LOADING_DURATION.getUnit())
.register(meterRegistry);
this.formDataWaitingDurationGauges = MultiGauge.builder("beholder_form_waiting_response_duration")
.description("Time between sending request and first received byte of data")
.baseUnit("millis")
this.formDataWaitingDurationGauges = MultiGauge.builder(Metric.WAITING_RESPONSE_DURATION.getName())
.description(Metric.WAITING_RESPONSE_DURATION.getDescription())
.baseUnit(Metric.WAITING_RESPONSE_DURATION.getUnit())
.register(meterRegistry);
this.formDataReceivingDuration = MultiGauge.builder("beholder_form_receiving_response_duration")
.description("Time between receiving first and last byte of data")
.baseUnit("millis")
this.formDataReceivingDuration = MultiGauge.builder(Metric.RECEIVING_RESPONSE_DURATION.getName())
.description(Metric.RECEIVING_RESPONSE_DURATION.getDescription())
.baseUnit(Metric.RECEIVING_RESPONSE_DURATION.getUnit())
.register(meterRegistry);
this.formDomCompleteDuration = MultiGauge.builder("beholder_form_dom_complete_duration")
.description("Time between sending request and fully rendered DOM")
.baseUnit("millis")
this.formDomCompleteDuration = MultiGauge.builder(Metric.DOM_COMPLETE_DURATION.getName())
.description(Metric.DOM_COMPLETE_DURATION.getDescription())
.baseUnit(Metric.DOM_COMPLETE_DURATION.getUnit())
.register(meterRegistry);
this.formLoadingCounters = new HashMap<>();
this.formLoadingFailedCounters = new HashMap<>();
}
public void updateMetrics(List<FormDataResponse> formDataResponses) {
@ -63,7 +55,6 @@ public class MetricsService {
updateFormDomCompleteDuration(formDataResponses);
updateResourceLoadingDuration(formDataResponses);
updateFormLoadingRequestsTotal(formDataResponses);
updateFormLoadingFailedRequestsTotal(formDataResponses);
log.debug("Updating beholder metrics finished");
}
@ -105,32 +96,18 @@ public class MetricsService {
private void updateFormLoadingRequestsTotal(List<FormDataResponse> formDataResponses) {
for (FormDataResponse response : formDataResponses) {
String id = MetricUtil.getCounterId(response);
Counter counter = formLoadingCounters.getOrDefault(id,
Counter.builder("beholder_form_loading_requests")
.description("Total requests for form upload")
.tags(MetricUtil.createCommonTags(response))
.baseUnit("total")
.register(meterRegistry));
counter.increment();
formLoadingCounters.put(id, counter);
Tags tags = MetricUtil.createCommonTags(response);
incrementFormLoadingCounter(tags.and("result", response.isFailed() ? "failure" : "success"));
}
}
private void updateFormLoadingFailedRequestsTotal(List<FormDataResponse> formDataResponses) {
for (FormDataResponse response : formDataResponses) {
if (response.isFailed()) {
String id = MetricUtil.getCounterId(response);
Counter counter = formLoadingFailedCounters.getOrDefault(id,
Counter.builder("beholder_form_loading_failed")
.description("Total failed requests for form upload")
.tags(MetricUtil.createCommonTags(response))
.baseUnit("total")
.register(meterRegistry));
counter.increment();
formLoadingFailedCounters.put(id, counter);
}
}
private void incrementFormLoadingCounter(Tags tags) {
Counter.builder(Metric.FORM_LOADING_REQUESTS.getName())
.description(Metric.FORM_LOADING_REQUESTS.getDescription())
.tags(tags)
.baseUnit(Metric.FORM_LOADING_REQUESTS.getUnit())
.register(meterRegistry)
.increment();
}
private void updateResourceLoadingDuration(List<FormDataResponse> formDataResponses) {

View File

@ -20,6 +20,8 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import static dev.vality.beholder.util.MetricUtil.castToDouble;
@Slf4j
@RequiredArgsConstructor
public class SeleniumService {
@ -96,18 +98,6 @@ public class SeleniumService {
ExpectedConditions.visibilityOfElementLocated(By.ById.id("success-icon")));
}
private Double castToDouble(Object object) {
if (object instanceof Double) {
return (Double) object;
} else if (object instanceof Long) {
return ((Long) object).doubleValue();
} else {
log.warn("Unable to cast {} to double", object);
}
return Double.NaN;
}
private String prepareParams(FormDataRequest formDataRequest) {
return UriComponentsBuilder.fromHttpUrl(formUrl)
.queryParam("invoiceAccessToken", formDataRequest.getInvoiceAccessToken())

View File

@ -52,7 +52,15 @@ public class MetricUtil {
"region", formDataResponse.getRegion().getCode());
}
public String getCounterId(FormDataResponse formDataResponse) {
return String.join("_", formDataResponse.getBrowser().name(), formDataResponse.getRegion().getCountry());
public static Double castToDouble(Object object) {
if (object instanceof Double) {
return (Double) object;
} else if (object instanceof Long) {
return ((Long) object).doubleValue();
} else {
log.warn("Unable to cast {} to double", object);
}
return Double.NaN;
}
}