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

feat: Add StepHistory class #88

Merged
merged 1 commit into from
Jun 15, 2021
Merged

feat: Add StepHistory class #88

merged 1 commit into from
Jun 15, 2021

Conversation

pgrzesik
Copy link
Contributor

Add StepHistory class as it has to be reused between dashboard-plugin and serverless

@pgrzesik pgrzesik self-assigned this Jun 15, 2021
@pgrzesik pgrzesik added the enhancement New feature or request label Jun 15, 2021
@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Merging #88 (12aff85) into master (0345ffe) will increase coverage by 0.17%.
The diff coverage is 100.00%.

❗ Current head 12aff85 differs from pull request most recent head bf8e142. Consider uploading reports for the commit bf8e142 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
+ Coverage   90.14%   90.31%   +0.17%     
==========================================
  Files          10       11       +1     
  Lines         284      289       +5     
==========================================
+ Hits          256      261       +5     
  Misses         28       28              
Impacted Files Coverage Δ
telemetry.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0345ffe...bf8e142. Read the comment docs.

@pgrzesik pgrzesik requested a review from medikoo June 15, 2021 09:31
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

@pgrzesik thanks for that. Still why do you think we need this to be introduced here?

I imagine that we will inject stepHistory instance in all cases here: https://github.com/serverless/serverless/blob/f4c9b58b10a45ae342934e9a61dcdea0c2ef11e2/lib/cli/interactive-setup/index.js#L19

And there will be no other places where this instance will be created (?)

@pgrzesik
Copy link
Contributor Author

pgrzesik commented Jun 15, 2021

It is needed in order to properly test steps in dashboard-plugin. Only other way is copying the code and maintaining it in both places. E.g. replacement for: https://github.com/serverless/dashboard-plugin/pull/598/files#diff-00b32d3b354274ba5868d467b461805ae8a33db5c40b9e3854771df1340d8520R125

@pgrzesik pgrzesik requested a review from medikoo June 15, 2021 09:39
@medikoo
Copy link
Contributor

medikoo commented Jun 15, 2021

Only other way is copying the code and maintaining it in both places. E.g. replacement for: https://github.com/serverless/dashboard-plugin/pull/598/files#diff-00b32d3b354274ba5868d467b461805ae8a33db5c40b9e3854771df1340d8520R125

And how exactly do you imagine testing this (?) I think at this level testing existence of timestamp is out of scope. We're just interested in confirming that given question was registered with given value, which could work as:

expect(Array.from(stepHistory).map(([key, value]) => [key, value.value])).to.deep.equal([
  ['orgName', '_user_provided_'],
  ['appName', '_user_provided_']
]);

We can also add helper on StepHistory, so no inline map is needed:

expect(stepHistory.valuesMap).to.deep.equal(new Map([
  ['orgName', '_user_provided_'],
  ['appName', '_user_provided_']
]));

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

After discussing it internally, all clear. I missed that we inject StepHistory instances to mocked context object.

Can we also have some sanity test? That adds few items and confirms toJSON output?

Also maybe it's worth to add valuesOnlyMap() method that could aid testing with values stripped of timestamps

telemetry.js Outdated
class StepHistory extends Map {
set(key, value) {
const valueWithTimestamp = {
...value,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be value: value ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've originally proposed an approach where the value is an object, but it's not used at the moment and I guess it will be better to stick to such approach

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if value is an object, I would still then store this value at value property.

At least top level should be just meta properties, and I think at this stage we do not see the use case for others (if there will be for ones to be injected with set may consider supporting them with third argument)

@pgrzesik pgrzesik force-pushed the add-step-history-class branch 2 times, most recently from 45e876d to 0c4b1af Compare June 15, 2021 10:33
@pgrzesik pgrzesik requested a review from medikoo June 15, 2021 10:34
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks very promising!

telemetry.js Outdated
set(key, value) {
const valueWithTimestamp = {
value,
timestamp: Math.round(Date.now() / 1000),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed - I took inspiration from how we record first installation of the Framework where we strip it to seconds, but here it makes more sense to have milliseconds

telemetry.js Outdated
}

toJSON() {
return Array.from(this.entries()).map(([key, obj]) => ({ question: key, ...obj }));
Copy link
Contributor

Choose a reason for hiding this comment

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

If we rename key to question. Shouldn't we rename value to answer (?)

I'm fine with both key/value and question/answer pairs. but I'm not sure about question/value pair.


Also, while we do not have such case now, key/value may play better, if we decide to rely on similar internal tracking with some other command. (e.g. imagine tracking packaging, first generating archives and then uploads, reporting it with question/answer feels bad)

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@pgrzesik pgrzesik merged commit 20b8df5 into master Jun 15, 2021
@pgrzesik pgrzesik deleted the add-step-history-class branch June 15, 2021 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants