Skip to content

Commit

Permalink
Fix tests and remove useless configuration in the HTTP receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu committed Oct 10, 2023
1 parent 42c4e8e commit aad1f03
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,5 @@
import org.apache.skywalking.oap.server.library.module.ModuleConfig;

public class ZipkinHTTPReceiverConfig extends ModuleConfig {
private String restHost;
private int restPort;
private String restContextPath;
private int restMaxThreads = 200;
private long restIdleTimeOut = 30000;
private int restAcceptQueueSize = 0;

public String getRestHost() {
return restHost;
}

public void setRestHost(String restHost) {
this.restHost = restHost;
}

public int getRestPort() {
return restPort;
}

public void setRestPort(int restPort) {
this.restPort = restPort;
}

public String getRestContextPath() {
return restContextPath;
}

public void setRestContextPath(String restContextPath) {
this.restContextPath = restContextPath;
}

public int getRestMaxThreads() {
return restMaxThreads;
}

public void setRestMaxThreads(int restMaxThreads) {
this.restMaxThreads = restMaxThreads;
}

public long getRestIdleTimeOut() {
return restIdleTimeOut;
}

public void setRestIdleTimeOut(long restIdleTimeOut) {
this.restIdleTimeOut = restIdleTimeOut;
}

public int getRestAcceptQueueSize() {
return restAcceptQueueSize;
}

public void setRestAcceptQueueSize(int restAcceptQueueSize) {
this.restAcceptQueueSize = restAcceptQueueSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
import org.apache.skywalking.oap.server.library.server.http.HTTPServer;
import org.apache.skywalking.oap.server.receiver.zipkin.handler.ZipkinSpanHTTPHandler;
import org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward;
import zipkin.server.core.services.ZipkinConfigService;
Expand All @@ -32,8 +31,7 @@

public class ZipkinHTTPReceiverProvider extends ModuleProvider {
private ZipkinHTTPReceiverConfig moduleConfig;
private SpanForward spanForward;
private HTTPServer httpServer;
private ZipkinSpanHTTPHandler httpHandler;

@Override
public String name() {
Expand Down Expand Up @@ -67,14 +65,15 @@ public void prepare() throws ServiceNotProvidedException, ModuleStartException {
@Override
public void start() throws ServiceNotProvidedException, ModuleStartException {
final ConfigService service = getManager().find(CoreModule.NAME).provider().getService(ConfigService.class);
this.spanForward = new SpanForward(((ZipkinConfigService)service).toZipkinReceiverConfig(), getManager());
final SpanForward spanForward = new SpanForward(((ZipkinConfigService)service).toZipkinReceiverConfig(), getManager());
httpHandler = new ZipkinSpanHTTPHandler(spanForward, getManager());

final HTTPHandlerRegister httpRegister = getManager().find(CoreModule.NAME).provider().getService(HTTPHandlerRegister.class);
httpRegister.addHandler(httpHandler, Arrays.asList(HttpMethod.POST, HttpMethod.GET));
}

@Override
public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
final HTTPHandlerRegister httpRegister = getManager().find(CoreModule.NAME).provider().getService(HTTPHandlerRegister.class);
httpRegister.addHandler(new ZipkinSpanHTTPHandler(this.spanForward, getManager()),
Arrays.asList(HttpMethod.POST, HttpMethod.GET));
}

@Override
Expand All @@ -83,4 +82,8 @@ public String[] requiredModules() {
CoreModule.NAME,
};
}

public ZipkinSpanHTTPHandler getHttpHandler() {
return httpHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.CoreModuleProvider;
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.server.HTTPHandlerRegister;
import org.apache.skywalking.oap.server.core.server.HTTPHandlerRegisterImpl;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.library.server.http.HTTPServer;
import org.apache.skywalking.oap.server.library.server.http.HTTPServerConfig;
import org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward;
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator;
Expand Down Expand Up @@ -66,26 +70,20 @@ public class ITHTTPReceiver {

@BeforeEach
public void setup() throws ModuleStartException {
final ZipkinHTTPReceiverConfig config = new ZipkinHTTPReceiverConfig();
config.setRestHost("0.0.0.0");
config.setRestPort(port);
config.setRestContextPath("/");
config.setRestIdleTimeOut(1000);
config.setRestMaxThreads(2);
config.setRestAcceptQueueSize(10);

moduleManager = setupModuleManager();
final HTTPServer httpServer = new HTTPServer(HTTPServerConfig.builder().host("0.0.0.0").port(port).contextPath("/").build());
httpServer.initialize();
moduleManager = setupModuleManager(httpServer);

final ZipkinHTTPReceiverProvider provider = new ZipkinHTTPReceiverProvider();
provider.setManager(moduleManager);
Whitebox.setInternalState(provider, ZipkinHTTPReceiverConfig.class, config);
provider.prepare();
provider.start();
httpServer.start();
doAnswer(invocationOnMock -> {
spans.add(invocationOnMock.getArgument(0, ArrayList.class));
return null;
}).when(forward).send(any());
Whitebox.setInternalState(provider, SpanForward.class, forward);
Whitebox.setInternalState(provider.getHttpHandler(), SpanForward.class, forward);
provider.notifyAfterCompleted();
}

Expand Down Expand Up @@ -115,13 +113,14 @@ public void test() throws Exception {
assertThat(spans.take()).containsExactly(CLIENT_SPAN);
}

private ModuleManager setupModuleManager() {
private ModuleManager setupModuleManager(HTTPServer httpServer) {
ModuleManager moduleManager = Mockito.mock(ModuleManager.class);

CoreModule coreModule = Mockito.spy(CoreModule.class);
CoreModuleProvider moduleProvider = Mockito.mock(CoreModuleProvider.class);
Whitebox.setInternalState(coreModule, "loadedProvider", moduleProvider);
Mockito.when(moduleManager.find(CoreModule.NAME)).thenReturn(coreModule);
Mockito.when(coreModule.provider().getService(HTTPHandlerRegister.class)).thenReturn(new HTTPHandlerRegisterImpl(httpServer));

TelemetryModule telemetryModule = Mockito.spy(TelemetryModule.class);
NoneTelemetryProvider noneTelemetryProvider = Mockito.mock(NoneTelemetryProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ core:
gRPCMaxConcurrentCallsPerConnection: ${ZIPKIN_GRPC_MAX_CONCURRENT_CALL:0}
gRPCMaxMessageSize: ${ZIPKIN_GRPC_MAX_MESSAGE_SIZE:0}
restHost: ${ZIPKIN_REST_HOST:0.0.0.0}
restPort: ${ZIPKIN_REST_PORT:9412}
restPort: ${ZIPKIN_REST_PORT:9411}
restContextPath: ${ZIPKIN_REST_CONTEXT_PATH:/zipkin}
restMaxThreads: ${ZIPKIN_REST_MAX_THREADS:200}
restIdleTimeOut: ${ZIPKIN_REST_IDLE_TIMEOUT:30000}
Expand Down Expand Up @@ -150,12 +150,6 @@ storage:
receiver-zipkin-http:
selector: ${ZIPKIN_RECEIVER_ZIPKIN_HTTP:default}
default:
restHost: ${ZIPKIN_RECEIVER_ZIPKIN_REST_HOST:0.0.0.0}
restPort: ${ZIPKIN_RECEIVER_ZIPKIN_REST_PORT:9411}
restContextPath: ${ZIPKIN_RECEIVER_ZIPKIN_REST_CONTEXT_PATH:/}
restMaxThreads: ${ZIPKIN_RECEIVER_ZIPKIN_REST_MAX_THREADS:200}
restIdleTimeOut: ${ZIPKIN_RECEIVER_ZIPKIN_REST_IDLE_TIMEOUT:30000}
restAcceptQueueSize: ${ZIPKIN_RECEIVER_ZIPKIN_REST_QUEUE_SIZE:0}

receiver-zipkin-kafka:
selector: ${ZIPKIN_RECEIVER_ZIPKIN_KAFKA:-}
Expand Down

0 comments on commit aad1f03

Please sign in to comment.