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

fix PagerDuty timestamp validation #122321

Merged
merged 4 commits into from Jan 12, 2022

Conversation

ersin-erdal
Copy link
Contributor

fixes: #116173

PagerDuty requires ISO 8601 format for the timestamp, native JS Date.parse method does not support some ISO-8601 formats. With this PR, we use moment for date validation.

@ersin-erdal ersin-erdal added release_note:fix v8.1.0 Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Jan 5, 2022
@pmuellr pmuellr added the Feature:Actions/ConnectorTypes Issues related to specific Connector Types on the Actions Framework label Jan 5, 2022
@ersin-erdal ersin-erdal added Feature:Actions/ConnectorsManagement Issues related to Connectors Management UX auto-backport Deprecated: Automatically backport this PR after it's merged v8.0.0 and removed Feature:Actions/ConnectorTypes Issues related to specific Connector Types on the Actions Framework labels Jan 5, 2022
@ersin-erdal ersin-erdal marked this pull request as ready for review January 5, 2022 14:16
@ersin-erdal ersin-erdal requested a review from a team as a code owner January 5, 2022 14:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job adding this validation to the server side! We should also fix it on the client side, where validation occurs in x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty/pagerduty.tsx

@ersin-erdal
Copy link
Contributor Author

After a discussion with Patrick, i changed the code a bit.
Now, it accepts all the valid date formats but converts it to ISO 8601 before sending it to PagerDuty.
In order to be consistent, Implemented the same moment validation method in frontend too.

@ymao1
Copy link
Contributor

ymao1 commented Jan 6, 2022

When I try 2021-10-22 5:01:32, I am getting this warning:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: 2021-10-22 5:01:32, _f: undefined, _strict: undefined, _locale: [object Object]

Although I see that it is formatted correctly as 2021-10-22T09:01:32.000Z in the PagerDuty payload. Are we concerned about this deprecation warning at all?

@ersin-erdal
Copy link
Contributor Author

Yes i saw that warning to, probably the single digit hour (5) caused it.
It's discouraged to pass non ISO formatted date to moment. https://momentjs.com/guides/#/warnings/js-date/
Maybe we should force users to enter a valid ISO formatted date?

@ymao1
Copy link
Contributor

ymao1 commented Jan 10, 2022

I like not forcing users to format their own timestamps and handling the formatting ourselves but just worried this deprecation will eventually turn into an error. WDYT @pmuellr?

@pmuellr
Copy link
Member

pmuellr commented Jan 10, 2022

I like not forcing users to format their own timestamps and handling the formatting ourselves but just worried this deprecation will eventually turn into an error. WDYT

Ya, it's an SDH generator :-)

I'm wondering if parsing with just Date.parse() would be good enough? These dates are all coming from ES fields, but I guess they could be in different formats stored there. Or are there other options in moment to not have that message displayed?

@ersin-erdal
Copy link
Contributor Author

That deprecation warning is shown when a non-ISO date string is passed to moment such as: moment("non-iso-date-string"), then moment fall backs to: moment(new Date("non-iso-date-string")). But that was discussed and the warning was added in 2014! See the original discussion: moment/moment#1407
After that, moment decided to not to release any major changes (basically it's done, we (kibana) better to switch to a new library such as date-fns) See the project status: https://momentjs.com/docs/#/-project-status/

So, i don't think that the fall back will be deprecated. And since the code is consistent and working as expected, we can merge this PR.

@ymao1
Copy link
Contributor

ymao1 commented Jan 11, 2022

So, i don't think that the fall back will be deprecated. And since the code is consistent and working as expected, we can merge this PR.

That's fair :)

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice job

@ersin-erdal
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 53.9KB 53.9KB -3.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Regarding the discussion of the deprecation message in moment, this may actually be useful, in case we ever hit it and wonder why a date may have been generated the way it was generated. Hopefully it would show up in the logs, but I imagine it's being written directly to stdout, so may not show up in all logging scenarios ...

@ersin-erdal ersin-erdal merged commit 1752caf into elastic:main Jan 12, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 12, 2022
* fix PagerDuty timestamp validation

* convert a valid timestamp to ISOString

* frontend validation

(cherry picked from commit 1752caf)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 12, 2022
* fix PagerDuty timestamp validation

* convert a valid timestamp to ISOString

* frontend validation

(cherry picked from commit 1752caf)

Co-authored-by: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com>
@ersin-erdal ersin-erdal deleted the 116173-pagerduty-timestamp branch February 8, 2022 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:alerting auto-backport Deprecated: Automatically backport this PR after it's merged Feature:Actions/ConnectorsManagement Issues related to Connectors Management UX Feature:Alerting release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Actions] Improve pager duty timestamp validation
7 participants