Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Отправка города в метриках, исправление parsing_started и parsing_finished #72

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void sendAllWines() {
for (WineDto wineDto : wineDtoList) {
wines.add(ProtobufConverter.getProtobufWine(wineDto));
}
amServiceMetricsCollector.countWinesPublishedToKafka(wines.size());
amServiceMetricsCollector.countWinesPublishedToKafka(wines.size(), "Санкт-Петербург");
List<List<ParserApi.Wine>> chunks = chunkify(wines, CHUNK_SIZE);

for(List<ParserApi.Wine> chunk : chunks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void sendWines() {
.addWines(ProtobufConverter.getProtobufWine(wineDto))
.build();
kafkaMessageSender.sendMessage(message);
amServiceMetricsCollector.countWinesPublishedToKafka(1);
amServiceMetricsCollector.countWinesPublishedToKafka(1, "Санкт-Петербург");
}

private WineDto wineToWineDto(Wine wine, Double oldPrice, Double price) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,30 @@ public void runJob() {
updateService.updateDictionary();
updateService.updateWines();
long jobEnd = System.nanoTime();
metricsCollector.jobExecutionTime(jobEnd - jobStart);
metricsCollector.jobExecutionTime(jobEnd - jobStart, "Санкт-Петербург");
}

@Scheduled(cron = "*/20 * * * * *")
@TrackExecutionTime(description = "Actualize wines Job")
public void parsePages() {
metricsCollector.countParsingStart("Санкт-Петербург");
metricsCollector.incParsingInProgress("Санкт-Петербург");
long fetchStart = System.nanoTime();
Document document = amClient.getPage(pageCursor.getAndIncrement());
long fetchEnd = System.nanoTime();
metricsCollector.timeWinePageFetchingDuration(fetchEnd - fetchStart);
metricsCollector.timeWinePageFetchingDuration(fetchEnd - fetchStart, "Санкт-Петербург");
if(document != null) {
final Long pageAmount = amService.getCatalogPagesAmount(document);
if(pageCursor.longValue() >= pageAmount) {
pageCursor.set(1L);
}
List<AmWine> wines = amService.getAmWines(document);
updateService.updateWines(wines);
metricsCollector.countParsingComplete("SUCCESS", "Санкт-Петербург");
} else {
metricsCollector.countParsingComplete("FAILURE", "Санкт-Петербург");
}
metricsCollector.decParsingInProgress("Санкт-Петербург");
}

@Scheduled(cron = "*/20 * * * * *")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Document getPageByUrl(String url) {
while (attempt < maxRetries) {
Document document = fetchPage(url);
if (document != null) {
metricsCollector.isBanned(0);
metricsCollector.isBanned(0, "Санкт-Петербург");
failedFetches = 0;
return document;
}
Expand All @@ -68,7 +68,7 @@ public Document getPageByUrl(String url) {
failedFetches++;
if(failedFetches >= 5 || url.equals(catalogUrl)) {
log.warn("The service appears to have been banned!");
metricsCollector.isBanned(1);
metricsCollector.isBanned(1, "Санкт-Петербург");
}
log.error("Cannot get document by '{}' url in {} attempts, there have been {} failed fetches in a row", url, attempt, failedFetches);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,27 @@ public List<AmWine> getAmWines() {
Long lastParse = null;

while (page <= pages) {
metricsCollector.countParsingStart();
metricsCollector.incParsingInProgress();
parseAttemptsCount++;
long pageCopy = page;
List<AmWine> newWines = getAmWines(page);
metricsCollector.parsedWinesSuccess(newWines.size());
metricsCollector.winesParsedUnsuccessful(18 - newWines.size());
metricsCollector.percentageOfUnsuccessfullyParsedWines(newWines.size() / 18);
metricsCollector.parsedWinesSuccess(newWines.size(), "Санкт-Петербург");
metricsCollector.winesParsedUnsuccessful(18 - newWines.size(), "Санкт-Петербург");
metricsCollector.percentageOfUnsuccessfullyParsedWines(newWines.size() / 18, "Санкт-Петербург");
page++;
amWines.addAll(newWines);
pagesProcessed[(int) pageCopy - 1] = true;
if (!newWines.isEmpty()) {
successfulParseCount++;
metricsCollector.countParsingComplete("SUCCESS");
eventLogger.info(AmServiceNotableEvents.I_WINES_PAGE_PARSED, pageCopy);
pagesWithParsedWines[(int) pageCopy - 1] = true;
long currentParse = System.nanoTime();
if(lastParse != null) {
metricsCollector.countTimeSinceLastParsing(currentParse - lastParse);
metricsCollector.countTimeSinceLastParsing(currentParse - lastParse, "Санкт-Петербург");
}
lastParse = currentParse;
} else {
metricsCollector.countParsingComplete("FAILED");
eventLogger.warn(AmServiceNotableEvents.W_WINE_PAGE_PARSING_FAILED, pageCopy, baseUrl + "?page=" + pageCopy);
}
metricsCollector.decParsingInProgress();
}

StringBuilder lostPagesLog = new StringBuilder("Unprocessed pages: ");
Expand Down Expand Up @@ -202,7 +197,7 @@ public AdditionalProps getAdditionalProps(String link) {
long fetchStart = System.nanoTime();
Document page = client.getPageByUrl(link);
long fetchEnd = System.nanoTime();
metricsCollector.timeWineDetailsFetchingDuration(fetchEnd - fetchStart);
metricsCollector.timeWineDetailsFetchingDuration(fetchEnd - fetchStart, "Санкт-Петербург");
if(page == null) {
eventLogger.info(AmServiceNotableEvents.W_WINE_DETAILS_PARSING_FAILED, link);
}
Expand All @@ -226,7 +221,7 @@ private AdditionalProps parseAdditionalProps(Document page) {
handleProp(prop, props);
}
long parseEnd = System.nanoTime();
metricsCollector.timeWineDetailsParsingDuration(parseEnd - parseStart);
metricsCollector.timeWineDetailsParsingDuration(parseEnd - parseStart, "Санкт-Петербург");
return props;
}

Expand Down Expand Up @@ -264,7 +259,7 @@ private List<AmWine> getAmWines(Long page) {
long fetchStart = System.nanoTime();
final Document document = client.getPage(page);
long fetchEnd = System.nanoTime();
metricsCollector.timeWinePageFetchingDuration(fetchEnd - fetchStart);
metricsCollector.timeWinePageFetchingDuration(fetchEnd - fetchStart, "Санкт-Петербург");
return getAmWines(document);
}

Expand All @@ -281,7 +276,7 @@ public List<AmWine> getAmWines(Document document) {
}) :
Collections.emptyList();
long parseEnd = System.nanoTime();
metricsCollector.timeWinePageParsingDuration(parseEnd - parseStart);
metricsCollector.timeWinePageParsingDuration(parseEnd - parseStart, "Санкт-Петербург");
return res;
} catch (JsonProcessingException e) {
log.error("Cannot parse wines with error: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void updateWines() {
long parseStart = System.nanoTime();
updateService.updateWines();
long parseEnd = System.nanoTime();
metricsCollector.timeParsingDuration(parseEnd - parseStart);
metricsCollector.timeParsingDuration(parseEnd - parseStart, "Санкт-Петербург");
}

@Override
Expand All @@ -56,7 +56,7 @@ public void updateAll() {
long parseStart = System.nanoTime();
updateService.updateWines();
long parseEnd = System.nanoTime();
metricsCollector.timeParsingDuration(parseEnd - parseStart);
metricsCollector.timeParsingDuration(parseEnd - parseStart, "Санкт-Петербург");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ public void updateWines(List<AmWine> wines) {
if (wine != null) {
saveWine(wine, amWine, now);
updated++;
metricsCollector.countNumberOfWinesUpdated();
metricsCollector.countNumberOfWinesUpdated("Санкт-Петербург");
} else {
wine = new Wine();
saveWine(wine, amWine, now);
created++;
metricsCollector.countNumberOfWinesCreated();
metricsCollector.countNumberOfWinesCreated("Санкт-Петербург");
}
}
List<Wine> wineForDeleted = wineRepository.findAllByDateRecIsNot(now);
for (Wine w : wineForDeleted) {
w.setActual(false);
wineRepository.save(w);
markForDeleted++;
metricsCollector.countNumberOfWinesDeleted();
metricsCollector.countNumberOfWinesDeleted("Санкт-Петербург");
}
log.info("created {} Wines", created);
log.info("updated {} Wines", updated);
Expand Down