mirror of https://github.com/halo-dev/halo
chore: disable the visit log writer (#3421)
#### What type of PR is this? /kind cleanup /area core /milestone 2.3.x #### What this PR does / why we need it: 移除 VisitLogWriter 的使用,不再记录访问日志,后续由 httptrace 去暴露指标 #### Does this PR introduce a user-facing change? ```release-note None ```pull/3390/head^2
parent
1a9e2f046a
commit
166a440df1
|
@ -20,10 +20,6 @@ import run.halo.app.event.post.DownvotedEvent;
|
||||||
import run.halo.app.event.post.UpvotedEvent;
|
import run.halo.app.event.post.UpvotedEvent;
|
||||||
import run.halo.app.event.post.VisitedEvent;
|
import run.halo.app.event.post.VisitedEvent;
|
||||||
import run.halo.app.extension.GroupVersion;
|
import run.halo.app.extension.GroupVersion;
|
||||||
import run.halo.app.infra.utils.HaloUtils;
|
|
||||||
import run.halo.app.infra.utils.IpAddressUtils;
|
|
||||||
import run.halo.app.metrics.MeterUtils;
|
|
||||||
import run.halo.app.metrics.VisitLogWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics counter endpoint.
|
* Metrics counter endpoint.
|
||||||
|
@ -36,7 +32,6 @@ import run.halo.app.metrics.VisitLogWriter;
|
||||||
public class TrackerEndpoint implements CustomEndpoint {
|
public class TrackerEndpoint implements CustomEndpoint {
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
private final VisitLogWriter visitLogWriter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RouterFunction<ServerResponse> endpoint() {
|
public RouterFunction<ServerResponse> endpoint() {
|
||||||
|
@ -94,9 +89,6 @@ public class TrackerEndpoint implements CustomEndpoint {
|
||||||
.doOnNext(counterRequest -> {
|
.doOnNext(counterRequest -> {
|
||||||
eventPublisher.publishEvent(new VisitedEvent(this, counterRequest.group(),
|
eventPublisher.publishEvent(new VisitedEvent(this, counterRequest.group(),
|
||||||
counterRequest.name(), counterRequest.plural()));
|
counterRequest.name(), counterRequest.plural()));
|
||||||
|
|
||||||
// async write visit log
|
|
||||||
writeVisitLog(request, counterRequest);
|
|
||||||
})
|
})
|
||||||
.then(ServerResponse.ok().build());
|
.then(ServerResponse.ok().build());
|
||||||
}
|
}
|
||||||
|
@ -139,27 +131,6 @@ public class TrackerEndpoint implements CustomEndpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeVisitLog(ServerRequest request, CounterRequest counterRequest) {
|
|
||||||
String logMessage = logMessage(request, counterRequest);
|
|
||||||
visitLogWriter.log(logMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String logMessage(ServerRequest request, CounterRequest counterRequest) {
|
|
||||||
String ipAddress = IpAddressUtils.getIpAddress(request);
|
|
||||||
String hostname = counterRequest.hostname();
|
|
||||||
String screen = counterRequest.screen();
|
|
||||||
String language = counterRequest.language();
|
|
||||||
String referrer = counterRequest.referrer();
|
|
||||||
String userAgent = HaloUtils.userAgentFrom(request);
|
|
||||||
String counterName =
|
|
||||||
MeterUtils.nameOf(counterRequest.group(), counterRequest.plural(),
|
|
||||||
counterRequest.name());
|
|
||||||
return String.format(
|
|
||||||
"subject=[%s], ipAddress=[%s], hostname=[%s], screen=[%s], language=[%s], "
|
|
||||||
+ "referrer=[%s], userAgent=[%s]", counterName, ipAddress, hostname, screen,
|
|
||||||
language, referrer, userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupVersion groupVersion() {
|
public GroupVersion groupVersion() {
|
||||||
return new GroupVersion("api.halo.run", "v1alpha1");
|
return new GroupVersion("api.halo.run", "v1alpha1");
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import reactor.core.Disposable;
|
import reactor.core.Disposable;
|
||||||
import run.halo.app.infra.properties.HaloProperties;
|
import run.halo.app.infra.properties.HaloProperties;
|
||||||
import run.halo.app.infra.utils.FileUtils;
|
import run.halo.app.infra.utils.FileUtils;
|
||||||
|
@ -29,7 +28,7 @@ import run.halo.app.infra.utils.FileUtils;
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Deprecated
|
||||||
public class VisitLogWriter implements InitializingBean, DisposableBean {
|
public class VisitLogWriter implements InitializingBean, DisposableBean {
|
||||||
private static final String LOG_FILE_NAME = "visits.log";
|
private static final String LOG_FILE_NAME = "visits.log";
|
||||||
private static final String LOG_FILE_LOCATION = "logs";
|
private static final String LOG_FILE_LOCATION = "logs";
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -21,6 +22,8 @@ import run.halo.app.infra.properties.HaloProperties;
|
||||||
* @author guqing
|
* @author guqing
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@Disabled
|
||||||
|
@Deprecated
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class VisitLogWriterTest {
|
class VisitLogWriterTest {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue