Skip to content

Commit

Permalink
Remove o11yphant dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ligangty committed Jul 18, 2024
1 parent fc5a981 commit ed178c6
Show file tree
Hide file tree
Showing 27 changed files with 1,704 additions and 722 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public void clearTrackingRecord( final String trackingId, final StoreType type,
public boolean sealTrackingRecord( String trackingId )
throws IndyClientException
{
http.connect();

HttpPost request = http.newRawPost( UrlUtils.buildUrl( http.getBaseUrl(), "/folo/admin", trackingId, "record" ) );
HttpResources resources = null;
try
Expand Down
21 changes: 10 additions & 11 deletions core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
<artifactId>jhttpc</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.util</groupId>
<artifactId>o11yphant-trace-api</artifactId>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.util</groupId>
<artifactId>o11yphant-trace-otel</artifactId>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.util</groupId>
<artifactId>o11yphant-trace-helper-jhttpc</artifactId>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.util</groupId>
<artifactId>o11yphant-metrics-common</artifactId>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand All @@ -65,9 +65,8 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.commonjava.indy</groupId>
<artifactId>indy-test-fixtures-core</artifactId>
<scope>test</scope>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

Expand Down
20 changes: 0 additions & 20 deletions core-java/src/main/java/org/commonjava/indy/client/core/Indy.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.commonjava.indy.inject.IndyVersioningProvider;
import org.commonjava.indy.model.core.io.IndyObjectMapper;
import org.commonjava.indy.stats.IndyVersioning;
import org.commonjava.o11yphant.trace.TraceManager;
import org.commonjava.o11yphant.trace.TracerConfiguration;
import org.commonjava.util.jhttpc.auth.PasswordManager;
import org.commonjava.util.jhttpc.model.SiteConfig;

Expand Down Expand Up @@ -213,10 +211,6 @@ public static final class Builder

private Map<String, String> mdcCopyMappings;

private TracerConfiguration existedTraceConfig;

private TraceManager existedTraceManager;

private Builder()
{
}
Expand Down Expand Up @@ -252,18 +246,6 @@ public Builder setObjectMapper( IndyObjectMapper objectMapper )
return this;
}

public Builder setExistedTraceConfig( TracerConfiguration existedTraceConfig )
{
this.existedTraceConfig = existedTraceConfig;
return this;
}

public Builder setExistedTraceManager( TraceManager traceManager )
{
this.existedTraceManager = traceManager;
return this;
}

public Builder setAuthenticator( IndyClientAuthenticator authenticator )
{
this.authenticator = authenticator;
Expand Down Expand Up @@ -291,8 +273,6 @@ public Indy build()
.setApiVersion( indy.getApiVersion() )
.setLocation( this.location )
.setPasswordManager( this.passwordManager )
.setExistedTraceConfig( this.existedTraceConfig )
.setExistedTraceManager( this.existedTraceManager )
.setMdcCopyMappings( this.mdcCopyMappings )
.setObjectMapper( this.objectMapper )
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
Expand All @@ -41,14 +40,12 @@
import org.apache.http.util.VersionInfo;
import org.commonjava.indy.client.core.auth.IndyClientAuthenticator;
import org.commonjava.indy.client.core.helper.HttpResources;
import org.commonjava.indy.client.core.metric.ClientMetricManager;
import org.commonjava.indy.client.core.metric.ClientMetrics;
import org.commonjava.indy.client.core.o11y.metric.ClientMetricManager;
import org.commonjava.indy.client.core.o11y.metric.ClientMetrics;
import org.commonjava.indy.client.core.o11y.trace.SpanningHttpFactory;
import org.commonjava.indy.inject.IndyVersioningProvider;
import org.commonjava.indy.model.core.ArtifactStore;
import org.commonjava.indy.model.core.io.IndyObjectMapper;
import org.commonjava.o11yphant.jhttpc.SpanningHttpFactory;
import org.commonjava.o11yphant.trace.TraceManager;
import org.commonjava.o11yphant.trace.TracerConfiguration;
import org.commonjava.util.jhttpc.HttpFactory;
import org.commonjava.util.jhttpc.HttpFactoryIfc;
import org.commonjava.util.jhttpc.JHttpCException;
Expand All @@ -69,15 +66,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY;
import static org.commonjava.indy.client.core.helper.HttpResources.cleanupResources;
import static org.commonjava.indy.client.core.helper.HttpResources.entityToString;
import static org.commonjava.indy.client.core.metric.ClientMetricConstants.HEADER_CLIENT_API;
import static org.commonjava.indy.client.core.metric.ClientMetricConstants.HEADER_CLIENT_TRACE_ID;
import static org.commonjava.indy.client.core.util.UrlUtils.buildUrl;
import static org.commonjava.indy.stats.IndyVersioning.HEADER_INDY_API_VERSION;

Expand Down Expand Up @@ -121,7 +115,8 @@ public IndyClientHttp( final IndyClientAuthenticator authenticator, final IndyOb
this( mapper, location, apiVersion );
this.mdcCopyMappings = mdcCopyMappings;
metricManager = new ClientMetricManager( location );
factory = new SpanningHttpFactory( new HttpFactory( authenticator ), metricManager.getTraceManager() );
factory = new SpanningHttpFactory( new HttpFactory( authenticator ),
metricManager.getTraceManager().orElse( null ) );
}

/**
Expand All @@ -135,7 +130,8 @@ public IndyClientHttp( final PasswordManager passwordManager, final IndyObjectMa
this( mapper, location, apiVersion );

metricManager = new ClientMetricManager( location );
factory = new SpanningHttpFactory( new HttpFactory( passwordManager ), metricManager.getTraceManager() );
factory = new SpanningHttpFactory( new HttpFactory( passwordManager ),
metricManager.getTraceManager().orElse( null ) );
}

private IndyClientHttp( final IndyObjectMapper mapper, SiteConfig location, String apiVersion )
Expand Down Expand Up @@ -166,10 +162,6 @@ public static final class Builder

private String apiVersion;

private TracerConfiguration existedTraceConfig;

private TraceManager existedTraceManager;

private Map<String, String> mdcCopyMappings;

private Builder()
Expand Down Expand Up @@ -206,18 +198,6 @@ public Builder setApiVersion( String apiVersion )
return this;
}

public Builder setExistedTraceConfig( TracerConfiguration existedTraceConfig )
{
this.existedTraceConfig = existedTraceConfig;
return this;
}

public Builder setExistedTraceManager( TraceManager traceManager )
{
this.existedTraceManager = traceManager;
return this;
}

public Builder setMdcCopyMappings( Map<String, String> mdcCopyMappings )
{
this.mdcCopyMappings = mdcCopyMappings;
Expand Down Expand Up @@ -257,23 +237,8 @@ public IndyClientHttp build()
factory = new HttpFactory( this.passwordManager );
}

ClientMetricManager metricManager;
if ( this.existedTraceManager != null )
{
metricManager = new ClientMetricManager( this.existedTraceManager );
}
else if ( this.existedTraceConfig != null )
{
metricManager = new ClientMetricManager( this.existedTraceConfig );
}
else
{
metricManager = new ClientMetricManager( location );
}

client.metricManager = metricManager;
client.factory = new SpanningHttpFactory( factory, metricManager.getTraceManager() );

client.metricManager = new ClientMetricManager( location );
client.factory = new SpanningHttpFactory( factory, client.metricManager.getTraceManager().orElse( null ) );
return client;
}
}
Expand All @@ -289,14 +254,6 @@ private void initUserAgent( final String apiVersion )
String.format( "Indy/%s (api: %s) via %s", indyVersion, apiVersion, hcUserAgent ) );
}

private String addClientTraceHeader()
{
String traceId = UUID.randomUUID().toString();
addDefaultHeader( HEADER_CLIENT_TRACE_ID, traceId );
addDefaultHeader( HEADER_CLIENT_API, String.valueOf( true ) );
return traceId;
}

private void addApiVersionHeader( String apiVersion )
{
if ( isNotBlank( apiVersion ) )
Expand All @@ -318,24 +275,6 @@ private void checkBaseUrl( String baseUrl )
}
}

/**
* Not used since migration to jHTTPc library
*/
@Deprecated
public void connect( final HttpClientConnectionManager connectionManager )
{
// NOP, now that we've moved to HttpFactory.
}

/**
* Not used since migration to jHTTPc library
*/
@Deprecated
public synchronized void connect()
{
// NOP, now that we've moved to HttpFactory.
}

public Map<String, String> head( final String path )
throws IndyClientException
{
Expand All @@ -347,7 +286,6 @@ public Map<String, String> head( final String path, final int... responseCodes )
{
HttpHead request = newJsonHead( buildUrl( baseUrl, path ) );

connect();
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
ClientMetrics metrics = metricManager.register( request );
Expand Down Expand Up @@ -401,8 +339,6 @@ public <T> T get( final String path, final Class<T> type )
HttpGet request = newJsonGet( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( request );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -450,7 +386,6 @@ public <T> T get( final String path, final TypeReference<T> typeRef )
HttpGet request = newJsonGet( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( request );

connect();
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -493,8 +428,6 @@ public HttpResources getRaw( final HttpGet req )
{
ClientMetrics metrics = metricManager.register( req );

connect();

addLoggingMDCToHeaders( req );
CloseableHttpResponse response = null;
try
Expand Down Expand Up @@ -529,8 +462,6 @@ public HttpResources getRaw( final String path, final Map<String, String> header
final HttpGet req = newRawGet( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( req );

connect();

CloseableHttpResponse response = null;
try
{
Expand Down Expand Up @@ -570,8 +501,6 @@ public void putWithStream( final String path, final InputStream stream, final in
final HttpPut put = newRawPut( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( put );

connect();

addLoggingMDCToHeaders( put );
final CloseableHttpClient client = newClient();
CloseableHttpResponse response = null;
Expand Down Expand Up @@ -625,7 +554,6 @@ public boolean put( final String path, final Object value, final int... response
ClientMetrics metrics = metricManager.register( put );

checkRequestValue( value );
connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
Expand Down Expand Up @@ -664,8 +592,6 @@ public HttpResources execute( HttpRequestBase request )
{
ClientMetrics metrics = metricManager.register( request );

connect();

addLoggingMDCToHeaders( request );
CloseableHttpResponse response = null;
try
Expand Down Expand Up @@ -702,7 +628,6 @@ public HttpResources postRaw( final String path, Object value, final Map<String,
ClientMetrics metrics = metricManager.register( req );

checkRequestValue( value );
connect();

CloseableHttpResponse response = null;
try
Expand Down Expand Up @@ -760,8 +685,6 @@ public <T> T postWithResponse( final String path, final Object value, final Clas

checkRequestValue( value );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -823,8 +746,6 @@ public <T> T postWithResponse( final String path, final Object value, final Type

checkRequestValue( value );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -887,8 +808,6 @@ public void delete( final String path, final int... responseCodes )
HttpDelete delete = newDelete( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( delete );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -929,8 +848,6 @@ public void deleteWithChangelog( final String path, final String changelog, fina
HttpDelete delete = newDelete( buildUrl( baseUrl, path ) );
ClientMetrics metrics = metricManager.register( delete );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down Expand Up @@ -984,8 +901,6 @@ public boolean exists( final String path, Supplier<Map<String, String>> querySup
HttpHead request = newJsonHead( buildUrl( baseUrl, querySupplier, path ) );
ClientMetrics metrics = metricManager.register( request );

connect();

CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try
Expand Down
Loading

0 comments on commit ed178c6

Please sign in to comment.