in usage-statistics-impl/src/jetbrains/buildServer/usageStatistics/impl/UsageStatisticsReporterImpl.java [54:120]
private boolean doReportStatistics(@NotNull final String data) {
if (!myServerResponsibility.canReportUsageStatistics()) {
LOG.debug("Server is not responsible for sending statistics");
return true;
}
try {
final AtomicReference<String> result = new AtomicReference<>();
String serverUrl = TeamCityProperties.getProperty("teamcity.usageStatistics.server.url", "https://teamcity-stats.services.jetbrains.com/report.html");
final HTTPRequestBuilder.Request post =
new HTTPRequestBuilder(serverUrl)
.allowNonSecureConnection(true)
.withDomainCheck(TeamCityProperties.getBooleanOrTrue("teamcity.usageStatistics.server.checkDomain"))
.withMethod("POST")
.withData(data.getBytes("UTF-8"))
.onErrorResponse((state, text) -> {
if (state == 404) {
LOG.info("Cannot send usage statistics to \"" + serverUrl + "\": server unavailable");
} else {
if (text != null) {
if (LOG.isDebugEnabled()) {
LOG.info("Cannot send usage statistics to \"" + serverUrl + "\": return code " + state + ", text: " + text);
} else {
LOG.info("Cannot send usage statistics to \"" + serverUrl + "\": return code " + state + ", text: " + StringUtil.truncateStringValueWithDotsAtEnd(text, 5000));
}
} else {
LOG.info("Cannot send usage statistics to \"" + serverUrl + "\": return code " + state);
}
}
})
.onSuccess(response -> result.set(response.getBodyAsString()))
.onException(ex -> {
LOG.warnAndDebugDetails("Cannot send usage statistics to \"" + serverUrl + "\"", ex);
})
.build();
myRequestHandler.doRequest(post);
if (result.get() == null) return false;
if (result.get().isEmpty()) {
LOG.info("Statistics server answered empty response");
return false;
}
final Element element = XmlUtil.from_s(result.get());
if (element.getChild("ok") != null) {
return true;
}
final Element ignored = element.getChild("ignored");
if (ignored != null) {
LOG.info("Usage statistics server has filtered the request: " + ignored.getText());
return true;
}
final Element error = element.getChild("error");
if (error != null) {
LOG.info("Statistics server failed to process usage data: " + error.getText());
return false;
}
return true;
} catch (UnsupportedEncodingException ignore) {
} catch (URISyntaxException e) {
LOG.info("Cannot send usage statistics: " + e.getMessage());
}
return false;
}