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

added validation checks for the werft API #9064

Closed
wants to merge 8 commits into from

Conversation

fullmetalrooster
Copy link
Contributor

@fullmetalrooster fullmetalrooster commented Apr 1, 2022

Description

This adds some validation test to the werft.ts API.

  • It checks if a phase is already present with the same name.
  • A list is added that contains information about the phases and their slices.
  • It checks if a slice has already been closed when a log entry is created with the same name.
  • It checks if all slices inside a phase has been closed when the phase is closed.

UPDATE (2022-04-06): This is also fixing #9100 by ending phases explicitly. I made it optional adding the name of the phase to end it.

Related Issue(s)

Fixes #8707 #9100

How to test

You can test the changes by violating a check that has been implemented by this commit.
Here are some examples:
This commit does not have any problems: https://werft.gitpod-dev.com/job/gitpod-build-wth-test.174/raw
This commit does not close all slices: https://werft.gitpod-dev.com/job/gitpod-build-wth-test.175/raw
This commit adds a log entry when the slice has already been closed: https://werft.gitpod-dev.com/job/gitpod-build-wth-test.176/raw
This commit creates a phase that has already been created: https://werft.gitpod-dev.com/job/gitpod-build-wth-test.178/raw

Release Notes

None

Documentation

@fullmetalrooster fullmetalrooster marked this pull request as draft April 1, 2022 11:28
@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch 2 times, most recently from 2caaedc to 174a93f Compare April 1, 2022 14:19
@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch from 2476559 to 80de070 Compare April 4, 2022 06:44
@fullmetalrooster fullmetalrooster marked this pull request as ready for review April 4, 2022 06:45
@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch 2 times, most recently from 3ce536e to 3d51b8a Compare April 4, 2022 06:52
@fullmetalrooster fullmetalrooster requested a review from a team April 4, 2022 07:05
@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch 6 times, most recently from dee0df7 to 66c200b Compare April 4, 2022 08:54
Copy link
Contributor

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

Nice improvements, looking forward to making slices and phases more consistent 🙂

I've made one first review round and found a couple of things that look a bit confusing. If others could also provide some feedback here, that would be awesome

Comment on lines +151 to 152
werft.done("job config");
werft.done(sliceId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks super weird to see two slices being closed together at the moment 🤔

Copy link
Member

Choose a reason for hiding this comment

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

This could be avoided if the above code would use sliceId for logging instead of "job config".

.werft/util/werft.ts Outdated Show resolved Hide resolved
.werft/util/werft.ts Outdated Show resolved Hide resolved
.werft/util/werft.ts Outdated Show resolved Hide resolved
.werft/util/werft.ts Outdated Show resolved Hide resolved
Comment on lines 122 to 138
// Create a new slice entry that is already closed if no prior entry exists
if (!this.phases[this.currentPhase].slices[slice]) {
this.phases[this.currentPhase].slices[slice] = { "closed": true };
} else if (this.phases[this.currentPhase].slices[slice].closed) {
throw new Error(`The slice "${slice}" has already been closed!`);
} else {
this.phases[this.currentPhase].slices[slice].closed = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be split into a separated method?

I'm still struggling to understand what is the goal here 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does happen that a new slice is opened with werft.done(). This should make sure that a slice is registered although it is closed directly and that a slice is not closed multiple times. Another way would be to enforce opening a new slice with werft.slice(<NAME>).

Copy link
Contributor

Choose a reason for hiding this comment

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

werft.done() opens a new slice? That doesn't seem right... I expect that a slice is only opened once we log something, or am I missing something here? 🤔

A good thing about splitting this into a new method is that we can keep methods small, and also give names to them. If we can't give a good name to a method, it probably means that it is too complex and could be made simpler 😅

@meysholdt meysholdt self-requested a review April 5, 2022 09:16
@fullmetalrooster
Copy link
Contributor Author

I can still see missing traces [1]. I take a deeper look and work on ending phases explicitly.
image

private globalSpanAttributes: SpanAttributes = {}

public phases: { [name: string]: { "span": Span, "closed": boolean, "slices": { [name: string]: { "closed": boolean, "span": Span } } } } = {}
Copy link
Member

Choose a reason for hiding this comment

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

Can you introduce a Type for this datastructure?

Copy link
Contributor Author

@fullmetalrooster fullmetalrooster Apr 11, 2022

Choose a reason for hiding this comment

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

I can do that. I have already proposed that in the issue [1].

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 created a light version of my datastructures for phases and slices to solve this.

.werft/util/werft.ts Outdated Show resolved Hide resolved
.werft/util/werft.ts Outdated Show resolved Hide resolved
.werft/util/werft.ts Outdated Show resolved Hide resolved
span.end()
delete this.sliceSpans[id]
})
public endPhase(name?: string) {
Copy link
Member

Choose a reason for hiding this comment

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

What's the use case for supporting name as a parameter?

It seems wrong because if I'm not mistaken only on phase can be open at a given time. This implies that this.currentPhase is always the phase that's being closed.

Copy link
Contributor Author

@fullmetalrooster fullmetalrooster Apr 11, 2022

Choose a reason for hiding this comment

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

Adding the name explicitly would make the code more readable and to which phase the current code belongs.

@fullmetalrooster
Copy link
Contributor Author

I just ran a build on this PR. I get this warning at the end. Can you fix that?

WARNING: The slice "observability" has not been closed!

I ran the build --with=vm=true and got a broken trace. But that should not block this PR.

That is the reason why we moved from an error that breaks the deployment process to a warning [1].

@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch 4 times, most recently from 3d61060 to 1e39a70 Compare April 11, 2022 10:07
@fullmetalrooster fullmetalrooster force-pushed the wulfthimm/werft-ts-should-throw-8707 branch from 1e39a70 to cf90a0b Compare April 12, 2022 07:34
@stale
Copy link

stale bot commented Apr 23, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label Apr 23, 2022
@stale stale bot closed this Apr 28, 2022
@meysholdt meysholdt reopened this Apr 29, 2022
@stale stale bot removed the meta: stale This issue/PR is stale and will be closed soon label Apr 29, 2022
@stale
Copy link

stale bot commented May 25, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label May 25, 2022
@stale stale bot closed this May 31, 2022
@mads-hartmann mads-hartmann deleted the wulfthimm/werft-ts-should-throw-8707 branch September 14, 2022 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta: stale This issue/PR is stale and will be closed soon release-note-none size/L team: devx
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

werft.ts should throw errors if API is not used properly
4 participants