48
48
import static software .amazon .awssdk .core .client .config .SdkClientOption .RETRY_STRATEGY ;
49
49
import static software .amazon .awssdk .core .client .config .SdkClientOption .SCHEDULED_EXECUTOR_SERVICE ;
50
50
import static software .amazon .awssdk .core .client .config .SdkClientOption .SYNC_HTTP_CLIENT ;
51
+ import static software .amazon .awssdk .core .internal .useragent .UserAgentConstant .HTTP ;
52
+ import static software .amazon .awssdk .core .internal .useragent .UserAgentConstant .INTERNAL_METADATA_MARKER ;
53
+ import static software .amazon .awssdk .core .internal .useragent .UserAgentConstant .IO ;
54
+ import static software .amazon .awssdk .core .internal .useragent .UserAgentConstant .RETRY_MODE ;
51
55
import static software .amazon .awssdk .utils .CollectionUtils .mergeLists ;
52
56
import static software .amazon .awssdk .utils .Validate .paramNotNull ;
53
57
71
75
import software .amazon .awssdk .annotations .SdkProtectedApi ;
72
76
import software .amazon .awssdk .annotations .SdkTestInternalApi ;
73
77
import software .amazon .awssdk .core .ClientEndpointProvider ;
78
+ import software .amazon .awssdk .core .ClientType ;
74
79
import software .amazon .awssdk .core .CompressionConfiguration ;
75
80
import software .amazon .awssdk .core .SdkPlugin ;
76
81
import software .amazon .awssdk .core .SdkSystemSetting ;
82
87
import software .amazon .awssdk .core .interceptor .ExecutionInterceptor ;
83
88
import software .amazon .awssdk .core .internal .http .loader .DefaultSdkAsyncHttpClientBuilder ;
84
89
import software .amazon .awssdk .core .internal .http .loader .DefaultSdkHttpClientBuilder ;
85
- import software .amazon .awssdk .core .internal .http .pipeline .stages .ApplyUserAgentStage ;
86
90
import software .amazon .awssdk .core .internal .http .pipeline .stages .CompressRequestStage ;
87
91
import software .amazon .awssdk .core .internal .interceptor .HttpChecksumValidationInterceptor ;
88
92
import software .amazon .awssdk .core .internal .retry .SdkDefaultRetryStrategy ;
93
+ import software .amazon .awssdk .core .internal .useragent .SdkClientUserAgentProperties ;
94
+ import software .amazon .awssdk .core .internal .useragent .SdkUserAgentBuilder ;
89
95
import software .amazon .awssdk .core .retry .RetryMode ;
90
96
import software .amazon .awssdk .core .retry .RetryPolicy ;
91
- import software .amazon .awssdk .core .util .SdkUserAgent ;
97
+ import software .amazon .awssdk .core .util .SystemUserAgent ;
92
98
import software .amazon .awssdk .http .ExecutableHttpRequest ;
93
99
import software .amazon .awssdk .http .HttpExecuteRequest ;
94
100
import software .amazon .awssdk .http .SdkHttpClient ;
108
114
import software .amazon .awssdk .utils .Either ;
109
115
import software .amazon .awssdk .utils .Lazy ;
110
116
import software .amazon .awssdk .utils .OptionalUtils ;
117
+ import software .amazon .awssdk .utils .StringUtils ;
111
118
import software .amazon .awssdk .utils .ThreadFactoryBuilder ;
112
119
import software .amazon .awssdk .utils .Validate ;
120
+ import software .amazon .awssdk .utils .http .SdkHttpUtils ;
113
121
114
122
/**
115
123
* An SDK-internal implementation of the methods in {@link SdkClientBuilder}, {@link SdkAsyncClientBuilder} and
@@ -283,7 +291,7 @@ private SdkClientConfiguration mergeGlobalDefaults(SdkClientConfiguration config
283
291
.lazyOption (PROFILE_FILE , conf -> conf .get (PROFILE_FILE_SUPPLIER ).get ())
284
292
.option (PROFILE_NAME ,
285
293
ProfileFileSystemSetting .AWS_PROFILE .getStringValueOrThrow ())
286
- .option (USER_AGENT_PREFIX , SdkUserAgent . create (). userAgent () )
294
+ .option (USER_AGENT_PREFIX , "" )
287
295
.option (USER_AGENT_SUFFIX , "" )
288
296
.option (CRC32_FROM_COMPRESSED_DATA_ENABLED , false )
289
297
.option (CONFIGURED_COMPRESSION_CONFIGURATION ,
@@ -384,7 +392,8 @@ protected SdkClientConfiguration invokePlugins(SdkClientConfiguration config) {
384
392
return config ;
385
393
}
386
394
387
- private String resolveRetryMode (RetryPolicy retryPolicy , RetryStrategy retryStrategy ) {
395
+ //TODO (useragent): Refactor this as part of moving value to business metrics (UA 2.1)
396
+ private static String resolveRetryMode (RetryPolicy retryPolicy , RetryStrategy retryStrategy ) {
388
397
if (retryPolicy != null ) {
389
398
return retryPolicy .retryMode ().toString ();
390
399
}
@@ -401,13 +410,32 @@ private String resolveRetryMode(RetryPolicy retryPolicy, RetryStrategy retryStra
401
410
}
402
411
403
412
private String resolveClientUserAgent (LazyValueSource config ) {
404
- String retryMode = resolveRetryMode (config .get (RETRY_POLICY ), config .get (RETRY_STRATEGY ));
405
- return ApplyUserAgentStage .resolveClientUserAgent (config .get (USER_AGENT_PREFIX ),
406
- config .get (INTERNAL_USER_AGENT ),
407
- config .get (CLIENT_TYPE ),
408
- config .get (SYNC_HTTP_CLIENT ),
409
- config .get (ASYNC_HTTP_CLIENT ),
410
- retryMode );
413
+ SdkClientUserAgentProperties clientProperties = new SdkClientUserAgentProperties ();
414
+
415
+ ClientType clientType = config .get (CLIENT_TYPE );
416
+ ClientType resolvedClientType = clientType == null ? ClientType .UNKNOWN : config .get (CLIENT_TYPE );
417
+
418
+ clientProperties .putProperty (RETRY_MODE , StringUtils .lowerCase (resolveRetryMode (config .get (RETRY_POLICY ),
419
+ config .get (RETRY_STRATEGY ))));
420
+ clientProperties .putProperty (INTERNAL_METADATA_MARKER , StringUtils .trimToEmpty (config .get (INTERNAL_USER_AGENT )));
421
+ clientProperties .putProperty (IO , StringUtils .lowerCase (resolvedClientType .name ()));
422
+ clientProperties .putProperty (HTTP , SdkHttpUtils .urlEncode (clientName (resolvedClientType ,
423
+ config .get (SYNC_HTTP_CLIENT ),
424
+ config .get (ASYNC_HTTP_CLIENT ))));
425
+
426
+ return SdkUserAgentBuilder .buildClientUserAgentString (SystemUserAgent .getOrCreate (), clientProperties );
427
+ }
428
+
429
+ private static String clientName (ClientType clientType , SdkHttpClient syncHttpClient , SdkAsyncHttpClient asyncHttpClient ) {
430
+ if (clientType == SYNC ) {
431
+ return syncHttpClient == null ? "null" : syncHttpClient .clientName ();
432
+ }
433
+
434
+ if (clientType == ASYNC ) {
435
+ return asyncHttpClient == null ? "null" : asyncHttpClient .clientName ();
436
+ }
437
+
438
+ return ClientType .UNKNOWN .name ();
411
439
}
412
440
413
441
private RetryStrategy resolveRetryStrategy (LazyValueSource config ) {
0 commit comments