-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Low
-
Component/s: Integrations - SDK - Java
-
None
-
1
-
Severity 3 - Minor
Issue Summary
For the Java SDK, we have checked and confirmed that the com.ifountain.opsgenie.client.util.ClientProxyConfiguration appears to have no effect on the behavior of the OpsGenieClient and is being discarded.
Additionally, our document is also misleading our customers as OpsGenieClient is not propagated to Alert API
https://docs.opsgenie.com/docs/opsgenie-java-api
Steps to Reproduce
- Please try to follow our doc https://docs.opsgenie.com/docs/opsgenie-java-api and the proxy configuration section.
- As you follow the document, you'll notice that the proxy settings are being discarded and have no effect on the result.
Expected Results
We expect the proxy settings to be applied
Actual Results
They are being discarded
Workaround
This is the boilerplate that the customer has to have in place to set the proxy separately for heartbeat and alerts. Please see it below:
public Command(@NonNull ApplicationConfiguration configuration) { // Cache configuration this.configuration = configuration; // Initialize OpsGenie client // In no circumstance shall a problem with OpsGenie impair the working of the agent try { // Get OpsGenie configuration ClientConfiguration opsGenieConfiguration = getOpsGenieConfiguration(configuration); // OpsGenie client is used for Ping API... opsGenieClient = new OpsGenieClient(opsGenieConfiguration); opsGenieClient.setApiKey(configuration.getOpsGenieConfiguration().getApiKey()); opsGenieClient.setRootUri(configuration.getOpsGenieConfiguration().getEndpoint()); // ... but unfortunately its settings are not inherited by Alert API, so we need to set them // rather verbosely... alertApi = opsGenieClient.alertV2(); var apiClient = alertApi.getApiClient(); apiClient.setApiKey(opsGenieClient.getApiKey()); apiClient.setConnectTimeout(opsGenieConfiguration.getConnectionTimeout()); if (opsGenieConfiguration.getClientProxyConfiguration()!=null) { apiClient.setHttpClient( new Client( new URLConnectionClientHandler( new OpsGenieConnectionFactory( opsGenieConfiguration.getClientProxyConfiguration().proxyHost, opsGenieConfiguration.getClientProxyConfiguration().proxyPort ) ) ) ); } } catch (Exception e) { logger.error("Could not initialize OpsGenie client: %s".formatted(e.getMessage())); opsGenieClient = null; alertApi = null; } } /** Provides the configuration fot OpsGenie client @param configuration - The application configuration holding OpsGenie settings @return ClientConfiguration of OpsGenie client */ private static ClientConfiguration getOpsGenieConfiguration(ApplicationConfiguration configuration) { var opsGenieConfiguration = new ClientConfiguration(); var settings = configuration.getOpsGenieConfiguration(); opsGenieConfiguration.setSocketTimeout(settings.getSocketTimeout()*1000); opsGenieConfiguration.setConnectionTimeout(settings.getConnectionTimeout()*1000); // The default client retries 3 times: we want to retry none opsGenieConfiguration.setRetryHandler(new OpsgenieRequestRetryHandler() { @Override public boolean retryRequest(HttpRequest httpRequest, OpsGenieHttpResponse opsGenieHttpResponse, int i) { return false; } @Override public boolean retryRequest(IOException e, int i, HttpContext httpContext) { return false; } }); if (settings.getProxyHost()!=null) { opsGenieConfiguration.setClientProxyConfiguration( new ClientProxyConfiguration(settings.getProxyHost(), settings.getProxyPort()) ); logger.info("OpsGenie proxy host set to %s".formatted(opsGenieConfiguration.getClientProxyConfiguration().getProxyHost())); logger.info("OpsGenie proxy port set to %d".formatted(opsGenieConfiguration.getClientProxyConfiguration().getProxyPort())); } logger.info("OpsGenie connection timeout set to %d".formatted(opsGenieConfiguration.getConnectionTimeout())); logger.info("OpsGenie socket timeout set to %d".formatted(opsGenieConfiguration.getConnectionTimeout())); return opsGenieConfiguration; } package com.kuehnenagel.customs.cwrepl.utils; import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory; import java.io.IOException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; public class OpsGenieConnectionFactory implements HttpURLConnectionFactory { private final String proxyHost; private final int proxyPort; Proxy proxy; public OpsGenieConnectionFactory(String proxyHost, int proxyPort) { this.proxyHost = proxyHost; this.proxyPort = proxyPort; } private void initializeProxy() { proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); } public HttpURLConnection getHttpURLConnection(URL url) throws IOException { initializeProxy(); return (HttpURLConnection) url.openConnection(proxy); } }