aws/aws-sdk-java

Enabling Metrics for the AWS SDK for Java failed without no error msg

ByiProX opened this issue · 4 comments

Upcoming End-of-Support

  • I acknowledge the upcoming end-of-support for AWS SDK for Java v1 was announced, and migration to AWS SDK for Java v2 is recommended.

Describe the issue

Hi, engineer.

Here is an problem of Enabling Metrics for the AWS SDK java v1.
I followed our official docs as below to enable Metrics for the AWS SDK, but no metric is sent to cloudwatch metrics.
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/generating-sdk-metrics.html

I have a test followed the official doc in both china(cn-north-1) and global(us-east-1 and ap-northeast-1) region and have tried several version of java sdk v1, but never successed to send data to cloudwatch metric.
.
Besides, I enabled java sdk detailed logs in my java code and can not find any requests log to cloudwatch service.(only see s3 debug log)
It seems that it is not enabled with the config: -Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=us-east-1

Can you tell me what I MIISSED with my java project? And Considering that aws java sdk v1 is an old version, does this feature is available for now?
You can see the java code and pom that I used in the attachement.

The pom described as bellow:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>aws-java-sdk-bom</artifactId>
                <version>1.11.700</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>


        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-cloudwatchmetrics</artifactId>
            <scope>provided</scope>
        </dependency>

java demo code

public static void main(String[] args) throws InterruptedException {
        BasicConfigurator.configure();
        System.out.println(System.getProperties());


        String accessKey = "xx";
        String secretKey = "xxxxx";
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);

        AmazonS3 mys3 = AmazonS3ClientBuilder.standard()
//                .withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("cn-north-1")
                .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).withRegion("us-east-1")
                .disableChunkedEncoding().build();
//        mys3.createBucket("kun-sdk-01");

        while (true) {

            List<Bucket> buckets = mys3.listBuckets();
            System.out.println(buckets);
            Thread.sleep(5000);
//            break;
        }
    }

Thanks for your help.

Links

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/generating-sdk-metrics.html

Hi, I have a test with this sdk and here is what I found.

As a workaround, I tried to enable this feature by adding
AwsSdkMetrics.enableDefaultMetrics();
before sending s3 requests and finally java sdk can send metrics to aws cloudwatch successfully.

However, adding system properties -Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=us-east-1 to jvm is not an effective method since now.
If it is, this may be a sdk issue.

Just for your reference.

-Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=us-east-1

If there's no error in the logs and no metrics are being published to Cloudwatch, my guess is that the system property is not being picked up by your application for some reason, or the application doesn't live long enough to send Cloudwatch metrics (metrics are pooled and sent every 2 minutes or so).

I tested the system property in my local machine and it is working normally, I tested us-east-1 and ap-northeast-1 regions.

If you still want to investigate this, you can try to increase the log level to see if more detailed errors show up when the metrics publisher try to send the requests to Cloudwatch.

Hi, debora.
Thanks for your reply.

I have a test in my local machine and still meet the issue.
Before you reply, I have run the application for a long time(0.5h) and enbled the debug level with the log4j tool.
Below is the config of log in my applicatiopn.

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c -  %m%n
# Turn on DEBUG logging in com.amazonaws.request to log
# a summary of requests/responses with {AWS} request IDs
log4j.logger.com.amazonaws.request=DEBUG

Can you provide the version of java and the java sdk, and do you pass the system property same as my method as below.
java -cp test.jar org.example.S3ClientDemo -Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=cn-north-1

Thanks for your help.

I believe system properties should go first:

java -Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=cn-north-1 -cp test.jar org.example.S3ClientDemo