Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
ByiProX opened this issue May 11, 2024 · 4 comments
Closed
1 task done

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

ByiProX opened this issue May 11, 2024 · 4 comments
Assignees
Labels
closed-for-staleness guidance Question that needs advice or information.

Comments

@ByiProX
Copy link

ByiProX commented May 11, 2024

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

@ByiProX ByiProX added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels May 11, 2024
@ByiProX
Copy link
Author

ByiProX commented May 13, 2024

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.

@debora-ito
Copy link
Member

debora-ito commented May 14, 2024

-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.

@debora-ito debora-ito added response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. and removed needs-triage This issue or PR still needs to be triaged. labels May 14, 2024
@debora-ito debora-ito self-assigned this May 14, 2024
@ByiProX
Copy link
Author

ByiProX commented May 16, 2024

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.

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label May 16, 2024
@debora-ito
Copy link
Member

I believe system properties should go first:

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

@debora-ito debora-ito added closing-soon This issue will close in 2 days unless further comments are made. guidance Question that needs advice or information. and removed documentation This is a problem with documentation. labels May 17, 2024
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will close in 2 days unless further comments are made. labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants