@Test(timeout = 30000) public void testDataDogUnifiedPortHandler() throws Exception { ddPort = findAvailablePort(4888); proxy.proxyConfig.dataDogJsonPorts = String.valueOf(ddPort); proxy.startDataDogListener(proxy.proxyConfig.getDataDogJsonPorts(), mockHandlerFactory, mockHttpClient); int ddPort2 = findAvailablePort(4988); PushAgent proxy2 = new PushAgent(); proxy2.proxyConfig.flushThreads = 2; proxy2.proxyConfig.dataBackfillCutoffHours = 100000000; proxy2.proxyConfig.dataDogJsonPorts = String.valueOf(ddPort2); proxy2.proxyConfig.dataDogRequestRelaySyncMode = true; proxy2.proxyConfig.dataDogProcessSystemMetrics = true; proxy2.proxyConfig.dataDogProcessServiceChecks = false; proxy2.proxyConfig.dataDogRequestRelayTarget = "http: assertEquals(Integer.valueOf(2), proxy2.proxyConfig.getFlushThreads()); assertTrue(proxy2.proxyConfig.isDataDogProcessSystemMetrics()); assertFalse(proxy2.proxyConfig.isDataDogProcessServiceChecks()); proxy2.startDataDogListener(proxy2.proxyConfig.getDataDogJsonPorts(), mockHandlerFactory, mockHttpClient); waitUntilListenerIsOnline(ddPort2); int ddPort3 = findAvailablePort(4990); PushAgent proxy3 = new PushAgent(); proxy3.proxyConfig.dataBackfillCutoffHours = 100000000; proxy3.proxyConfig.dataDogJsonPorts = String.valueOf(ddPort3); proxy3.proxyConfig.dataDogProcessSystemMetrics = true; proxy3.proxyConfig.dataDogProcessServiceChecks = true; assertTrue(proxy3.proxyConfig.isDataDogProcessSystemMetrics()); assertTrue(proxy3.proxyConfig.isDataDogProcessServiceChecks()); proxy3.startDataDogListener(proxy3.proxyConfig.getDataDogJsonPorts(), mockHandlerFactory, mockHttpClient); waitUntilListenerIsOnline(ddPort3); HttpResponse mockHttpResponse = EasyMock.createMock(HttpResponse.class); StatusLine mockStatusLine = EasyMock.createMock(StatusLine.class); reset(mockPointHandler, mockHttpClient, mockHttpResponse, mockStatusLine); expect(mockStatusLine.getStatusCode()).andReturn(200); expect(mockHttpResponse.getStatusLine()).andReturn(mockStatusLine); expect(mockHttpResponse.getEntity()).andReturn(new StringEntity("")); expect(mockHttpClient.execute(anyObject(HttpPost.class))).andReturn(mockHttpResponse); mockPointHandler.report(anyObject()); expectLastCall().times(46); replay(mockHttpClient, mockHttpResponse, mockStatusLine, mockPointHandler); gzippedHttpPost("http: verify(mockHttpClient, mockPointHandler); reset(mockPointHandler); mockPointHandler.report(anyObject()); expectLastCall().andThrow(new AssertionFailedError()).anyTimes(); replay(mockPointHandler); gzippedHttpPost("http: verify(mockPointHandler); reset(mockPointHandler, mockHttpClient, mockHttpResponse, mockStatusLine); expect(mockStatusLine.getStatusCode()).andReturn(404); expect(mockHttpResponse.getStatusLine()).andReturn(mockStatusLine); expect(mockHttpResponse.getEntity()).andReturn(new StringEntity("")); expect(mockHttpClient.execute(anyObject(HttpPost.class))).andReturn(mockHttpResponse); mockPointHandler.report(anyObject()); expectLastCall().andThrow(new AssertionFailedError()).anyTimes(); replay(mockHttpClient, mockHttpResponse, mockStatusLine, mockPointHandler); gzippedHttpPost("http: verify(mockHttpClient, mockPointHandler); reset(mockPointHandler, mockHttpClient, mockHttpResponse, mockStatusLine); expect(mockStatusLine.getStatusCode()).andReturn(202); expect(mockHttpResponse.getStatusLine()).andReturn(mockStatusLine); expect(mockHttpResponse.getEntity()).andReturn(new StringEntity("")); expect(mockHttpClient.execute(anyObject(HttpPost.class))).andReturn(mockHttpResponse); mockPointHandler.report(anyObject()); expectLastCall().andThrow(new AssertionFailedError()).anyTimes(); replay(mockHttpClient, mockHttpResponse, mockStatusLine, mockPointHandler); gzippedHttpPost("http: verify(mockHttpClient, mockPointHandler); reset(mockPointHandler); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("testApp.status"). setHost("testhost"). setTimestamp(1536719228000L). setValue(3.0d). build()); expectLastCall().once(); replay(mockPointHandler); gzippedHttpPost("http: verify(mockPointHandler); reset(mockPointHandler); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("system.net.tcp.retrans_segs"). setHost("testhost"). setTimestamp(1531176936000L). setValue(0.0d). setAnnotations(ImmutableMap.of("app", "closedstack", "role", "control")). build()); expectLastCall().once(); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("system.net.tcp.listen_drops"). setHost("testhost"). setTimestamp(1531176936000L). setValue(0.0d). setAnnotations(ImmutableMap.of("_source", "Launcher", "env", "prod", "app", "openstack", "role", "control")). build()); expectLastCall().once(); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("system.net.packets_in.count"). setHost("testhost"). setTimestamp(1531176936000L). setValue(12.052631578947368d). setAnnotations(ImmutableMap.of("device", "eth0", "app", "closedstack", "role", "control")). build()); expectLastCall().once(); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("test.metric"). setHost("testhost"). setTimestamp(1531176936000L). setValue(400.0d). setAnnotations(ImmutableMap.of("app", "closedstack", "role", "control")). build()); expectLastCall().once(); replay(mockPointHandler); gzippedHttpPost("http: gzippedHttpPost("http: verify(mockPointHandler); reset(mockPointHandler); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("testApp.status"). setHost("testhost"). setTimestamp(1536719228000L). setValue(3.0d). build()); expectLastCall().once(); mockPointHandler.report(ReportPoint.newBuilder(). setTable("dummy"). setMetric("testApp2.status"). setHost("testhost2"). setTimestamp(1536719228000L). setValue(2.0d). build()); expectLastCall().once(); replay(mockPointHandler); gzippedHttpPost("http: getResource("ddTestMultipleServiceChecks.json")); verify(mockPointHandler); }
protected void startDataDogListener(final String strPort, ReportableEntityHandlerFactory handlerFactory, HttpClient httpClient) { if (tokenAuthenticator.authRequired()) { logger.warning("Port: " + strPort + " (DataDog) is not compatible with HTTP authentication, ignoring"); return; } int port = Integer.parseInt(strPort); registerPrefixFilter(strPort); registerTimestampFilter(strPort); if (proxyConfig.isHttpHealthCheckAllPorts()) healthCheckManager.enableHealthcheck(port); ChannelHandler channelHandler = new DataDogPortUnificationHandler(strPort, healthCheckManager, handlerFactory, proxyConfig.getDataDogRequestRelayAsyncThreads(), proxyConfig.isDataDogRequestRelaySyncMode(), proxyConfig.isDataDogProcessSystemMetrics(), proxyConfig.isDataDogProcessServiceChecks(), httpClient, proxyConfig.getDataDogRequestRelayTarget(), preprocessors.get(strPort)); startAsManagedThread(port, new TcpIngester(createInitializer(channelHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port). withChildChannelOptions(childChannelOptions), "listener-plaintext-datadog-" + port); logger.info("listening on port: " + strPort + " for DataDog metrics"); }
PushAgent extends AbstractAgent { protected void startDataDogListener(final String strPort, ReportableEntityHandlerFactory handlerFactory, HttpClient httpClient) { if (tokenAuthenticator.authRequired()) { logger.warning("Port: " + strPort + " (DataDog) is not compatible with HTTP authentication, ignoring"); return; } int port = Integer.parseInt(strPort); registerPrefixFilter(strPort); registerTimestampFilter(strPort); if (proxyConfig.isHttpHealthCheckAllPorts()) healthCheckManager.enableHealthcheck(port); ChannelHandler channelHandler = new DataDogPortUnificationHandler(strPort, healthCheckManager, handlerFactory, proxyConfig.getDataDogRequestRelayAsyncThreads(), proxyConfig.isDataDogRequestRelaySyncMode(), proxyConfig.isDataDogProcessSystemMetrics(), proxyConfig.isDataDogProcessServiceChecks(), httpClient, proxyConfig.getDataDogRequestRelayTarget(), preprocessors.get(strPort)); startAsManagedThread(port, new TcpIngester(createInitializer(channelHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port). withChildChannelOptions(childChannelOptions), "listener-plaintext-datadog-" + port); logger.info("listening on port: " + strPort + " for DataDog metrics"); } }
PushAgent extends AbstractAgent { protected void startDataDogListener(final String strPort, ReportableEntityHandlerFactory handlerFactory, HttpClient httpClient) { if (tokenAuthenticator.authRequired()) { logger.warning("Port: " + strPort + " (DataDog) is not compatible with HTTP authentication, ignoring"); return; } int port = Integer.parseInt(strPort); registerPrefixFilter(strPort); registerTimestampFilter(strPort); if (proxyConfig.isHttpHealthCheckAllPorts()) healthCheckManager.enableHealthcheck(port); ChannelHandler channelHandler = new DataDogPortUnificationHandler(strPort, healthCheckManager, handlerFactory, proxyConfig.getDataDogRequestRelayAsyncThreads(), proxyConfig.isDataDogRequestRelaySyncMode(), proxyConfig.isDataDogProcessSystemMetrics(), proxyConfig.isDataDogProcessServiceChecks(), httpClient, proxyConfig.getDataDogRequestRelayTarget(), preprocessors.get(strPort)); startAsManagedThread(port, new TcpIngester(createInitializer(channelHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port). withChildChannelOptions(childChannelOptions), "listener-plaintext-datadog-" + port); logger.info("listening on port: " + strPort + " for DataDog metrics"); }  }
PushAgent extends AbstractAgent { protected void startDataDogListener(final String strPort, ReportableEntityHandlerFactory handlerFactory, HttpClient httpClient) { if (tokenAuthenticator.authRequired()) { logger.warning("Port: " + strPort + " (DataDog) is not compatible with HTTP authentication, ignoring"); return; } int port = Integer.parseInt(strPort); registerPrefixFilter(strPort); registerTimestampFilter(strPort); if (proxyConfig.isHttpHealthCheckAllPorts()) healthCheckManager.enableHealthcheck(port); ChannelHandler channelHandler = new DataDogPortUnificationHandler(strPort, healthCheckManager, handlerFactory, proxyConfig.getDataDogRequestRelayAsyncThreads(), proxyConfig.isDataDogRequestRelaySyncMode(), proxyConfig.isDataDogProcessSystemMetrics(), proxyConfig.isDataDogProcessServiceChecks(), httpClient, proxyConfig.getDataDogRequestRelayTarget(), preprocessors.get(strPort)); startAsManagedThread(port, new TcpIngester(createInitializer(channelHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port). withChildChannelOptions(childChannelOptions), "listener-plaintext-datadog-" + port); logger.info("listening on port: " + strPort + " for DataDog metrics"); }  static void main(String[] args); @Override void stopListeners(); }
PushAgent extends AbstractAgent { protected void startDataDogListener(final String strPort, ReportableEntityHandlerFactory handlerFactory, HttpClient httpClient) { if (tokenAuthenticator.authRequired()) { logger.warning("Port: " + strPort + " (DataDog) is not compatible with HTTP authentication, ignoring"); return; } int port = Integer.parseInt(strPort); registerPrefixFilter(strPort); registerTimestampFilter(strPort); if (proxyConfig.isHttpHealthCheckAllPorts()) healthCheckManager.enableHealthcheck(port); ChannelHandler channelHandler = new DataDogPortUnificationHandler(strPort, healthCheckManager, handlerFactory, proxyConfig.getDataDogRequestRelayAsyncThreads(), proxyConfig.isDataDogRequestRelaySyncMode(), proxyConfig.isDataDogProcessSystemMetrics(), proxyConfig.isDataDogProcessServiceChecks(), httpClient, proxyConfig.getDataDogRequestRelayTarget(), preprocessors.get(strPort)); startAsManagedThread(port, new TcpIngester(createInitializer(channelHandler, port, proxyConfig.getPushListenerMaxReceivedLength(), proxyConfig.getPushListenerHttpBufferSize(), proxyConfig.getListenerIdleConnectionTimeout(), getSslContext(strPort), getCorsConfig(strPort)), port). withChildChannelOptions(childChannelOptions), "listener-plaintext-datadog-" + port); logger.info("listening on port: " + strPort + " for DataDog metrics"); }  static void main(String[] args); @Override void stopListeners();  }