Skip to content

Commit

Permalink
HPCC4J-612 Code review
Browse files Browse the repository at this point in the history
- Removes commented out lines
- Adds WithSpan annotations to wsclientpool
- Adds hascredentials span attribute to current span
- Ensures executeECLScript is traced

Signed-off-by: Pastrana <[email protected]>
  • Loading branch information
Pastrana authored and Pastrana committed Sep 12, 2024
1 parent f68e38b commit 918310a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.hpccsystems.ws.client.utils.Connection;
import org.hpccsystems.ws.client.utils.ObjectPool;

//import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.instrumentation.annotations.WithSpan;

/**
* <p>HPCCWsClientPool class.</p>
Expand Down Expand Up @@ -78,7 +78,7 @@ public HPCCWsClientPool(Connection connection)
* @param timeout
* the timeout
*/
//@WithSpan
@WithSpan
public HPCCWsClientPool(Connection connection, long timeout)
{
super(timeout);
Expand All @@ -92,7 +92,7 @@ public HPCCWsClientPool(Connection connection, long timeout)
*/
/** {@inheritDoc} */
@Override
//@WithSpan
@WithSpan
protected HPCCWsClient create()
{
return (new HPCCWsClient(m_connection));
Expand All @@ -105,6 +105,7 @@ protected HPCCWsClient create()
*/
/** {@inheritDoc} */
@Override
@WithSpan
public boolean validate(HPCCWsClient client)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;

//import io.opentelemetry.instrumentation.annotations.WithSpan;

/**
* Facilitates access to HPCC Systems key/value based Storage.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,61 +1065,50 @@ public String sendHTTPRequest(@SpanAttribute String uri, @SpanAttribute String m

URL url = new URL (getBaseUrl() + (uri != null && uri.startsWith("/") ? "" : "/") + uri);

/*Span sendHTTPReqSpan = GlobalOpenTelemetry.get().getTracer(BaseHPCCWsClient.PROJECT_NAME)
.spanBuilder(method.toUpperCase() + " " + url.toExternalForm())
.setAttribute(ServerAttributes.SERVER_ADDRESS, getHost())
.setAttribute(ServerAttributes.SERVER_PORT, Long.getLong(getPort()))
.setAttribute(HttpAttributes.HTTP_REQUEST_METHOD, method)
.setSpanKind(SpanKind.CLIENT)
.startSpan();
*/
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); //throws IOException

Connection.log.info("Sending HTTP " + method + "Request to:" + url.toString());

boolean isTraced = Span.current().isRecording();
if (hasCredentials())
{
httpURLConnection.setRequestProperty("Authorization", getBasicAuthString());
//sendHTTPReqSpan.setAttribute("hasCredentials", true);
if (isTraced)
Span.current().setAttribute("hasCredentials", true);
}
//else
//{
//sendHTTPReqSpan.setAttribute("hasCredentials", false);
//}

//try (Scope scope = sendHTTPReqSpan.makeCurrent())
else
{
httpURLConnection.setRequestProperty("traceparent", Utils.getCurrentSpanTraceParentHeader());
httpURLConnection.setRequestMethod(method); //throws ProtocolException
if (isTraced)
Span.current().setAttribute("hasCredentials", false);
}

int responseCode = httpURLConnection.getResponseCode(); //throws IOException
//sendHTTPReqSpan.setAttribute("http.response.status_code", responseCode);
Connection.log.info("HTTP Response code: " + responseCode);
if (isTraced)
httpURLConnection.setRequestProperty("traceparent", Utils.getCurrentSpanTraceParentHeader());

if (responseCode == HttpURLConnection.HTTP_OK) //success
{
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); //throws IOException
String inputLine;
StringBuffer response = new StringBuffer();
httpURLConnection.setRequestMethod(method); //throws ProtocolException

while ((inputLine = in.readLine()) != null) // throws IOException
{
response.append(inputLine);
}
int responseCode = httpURLConnection.getResponseCode(); //throws IOException

in.close(); //throws IOException
// sendHTTPReqSpan.setStatus(StatusCode.OK);
return response.toString();
}
else
Connection.log.info("HTTP Response code: " + responseCode);

if (responseCode == HttpURLConnection.HTTP_OK) //success
{
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); //throws IOException
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) // throws IOException
{
//sendHTTPReqSpan.setStatus(StatusCode.ERROR);
throw new IOException("HTTP request failed! Code (" + responseCode + ") " + httpURLConnection.getResponseMessage() );
response.append(inputLine);
}

in.close(); //throws IOException

return response.toString();
}
else
{
throw new IOException("HTTP request failed! Code (" + responseCode + ") " + httpURLConnection.getResponseMessage() );
}
//finally
//{
// sendHTTPReqSpan.end();
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;

@Category(org.hpccsystems.commons.annotations.RemoteTests.class)
Expand Down Expand Up @@ -285,6 +286,7 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
}
}

@WithSpan
public static String executeECLScript(String eclFile) throws Exception
{
InputStream resourceStream = BaseRemoteTest.class.getClassLoader().getResourceAsStream(eclFile);
Expand Down

0 comments on commit 918310a

Please sign in to comment.