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

client-cloudwatch not taking milliseconds since 1970 #6862

Open
3 of 4 tasks
codermpl opened this issue Feb 4, 2025 · 6 comments
Open
3 of 4 tasks

client-cloudwatch not taking milliseconds since 1970 #6862

codermpl opened this issue Feb 4, 2025 · 6 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue

Comments

@codermpl
Copy link

codermpl commented Feb 4, 2025

Checkboxes for prior research

Describe the bug

client-cloudwatch MetricDatum interface says.

    /**
     * <p>The time the metric data was received, expressed as the number of milliseconds
     *             since Jan 1, 1970 00:00:00 UTC.</p>
     * @public
     */
    Timestamp?: Date | undefined;

This seems to be conflicting. The comment says it should take number of ms, but the type signature says it should take a Date object. API documentation confirms it's supposed to take ms since 1970: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html

I'd be happy if it could take either Date or ms as a number. But seems like it should at least take ms since that's what the API spec says.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

"@aws-sdk/client-cloudwatch": "^3.734.0",

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

22

Reproduction Steps

Pass a number in Timestamp field for PutMetricData

Observed Behavior

Fails

Expected Behavior

Timestamp property accepts ms since 1970

Possible Solution

Allow passing either a Date or number to the Timestamp property.

Additional Information/Context

No response

@codermpl codermpl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 4, 2025
@aBurmeseDev aBurmeseDev self-assigned this Feb 4, 2025
@aBurmeseDev
Copy link
Member

Hi @codermpl - thanks for reaching out.

Which SDK language are you using and are you running into any issue? Could you share your code snippet along with the error if any?

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Feb 8, 2025
@codermpl
Copy link
Author

language is typescript

@codermpl
Copy link
Author

code example:

  const input: PutMetricDataInput = {
    Namespace: 'abc',
    MetricData: [{ MetricName: 'name', Timestamp: Date.now() }],
  };

Type 'number' is not assignable to type 'Date'.ts(2322)

@aBurmeseDev
Copy link
Member

Date.now() returns a number where Timestamp expects Date object. Try this:

const input: PutMetricDataInput = {
    Namespace: 'abc',
    MetricData: [{ 
        MetricName: 'name', 
        Timestamp: new Date() // Convert to Date object or alternative new Date(Date.now()) 
    }],
};

@aBurmeseDev aBurmeseDev added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Feb 11, 2025
@codermpl
Copy link
Author

Yes, that's the bug. It expects a Date, but it's supposed to expect a number.

* <p>The time the metric data was received, expressed as the number of milliseconds
 *             since Jan 1, 1970 00:00:00 UTC.</p>

@aBurmeseDev
Copy link
Member

Based on the service model, it expects Date and I reached out to service team to confirm. It may be the docs that causes confusion. I'll circle back when I hear back from service team.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

2 participants