Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Add ability to create new environments and images to the coder-sdk#100

Merged
f0ssel merged 1 commit intomasterfromstress-sdk
Aug 28, 2020

Conversation

f0ssel
Copy link
Contributor

These new public functions will be used for our new load testing harness for the enterprise product

@f0sself0ssel changed the titleAdd ability to create new environments and imagesAdd ability to create new environments and images to the coder-sdkAug 21, 2020
Copy link
Contributor

@cmoogcmoog left a comment

Choose a reason for hiding this comment

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

Looks good to me. Not that I have a strong opinion, but it'd be nice to settle on a pointer/non-pointer convention for params/return values before we ask users to use this package.

conn, resp, err := websocket.Dial(ctx, u.String(),
&websocket.DialOptions{
HTTPHeader: map[string][]string{
"Cookie": {"session_token=" + c.Token},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can just use theSession-Token header instead of emulating cookies.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

👍

}

// WatchEnvironmentStats watches the environment update websocket for a given duration.
func (c Client) WatchEnvironmentStats(ctx context.Context, envID string, duration time.Duration) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

How are clients supposed to use this? It doesn't seem like anything is being done with the stats we're sent over the websocket

cmoog reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

True true. Should return a receive-only channel.

Copy link
Contributor

@coadlercoadlerAug 21, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think this would be much more useful if it returned some sort ofEnvStatsWatcher tied to the passedctx, so users canRead() orClose() themselves. Passing a duration seems hard to use and redundant since callers can use their owncontext.WithTimeout.

I tend to enjoy structs > bare channels so there's no need for selects, and so theRead function can return an error.

cmoog and fuskovic reacted with thumbs up emoji
Copy link
Contributor

@fuskovicfuskovicAug 26, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think we could probably return some data-structure here that implementsio.ReadCloser to piggy back on@coadler 's point.

Comment on lines 183 to 187
case <-statsCtx.Done():
return nil
default:
m := stats{}
err = wsjson.Read(ctx, conn, &m)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just passstatsCtx intowsjson.Read instead of using a select?

cmoog and fuskovic reacted with thumbs up emoji
Copy link
Contributor

@fuskovicfuskovic left a comment

Choose a reason for hiding this comment

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

Is it cool if we hold off on merging this until Monday?

I'd like to test it against4792 after I finish making the suggested changes and then I'll be able to provide better feedback on this.

Comment on lines 178 to 180
statsCtx, statsCancel := context.WithTimeout(ctx, duration)
defer statsCancel()

Copy link
Contributor

Choose a reason for hiding this comment

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

watching cancelation should happen through the context passed above, not a new context created by theduration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this one@cmoog

I think if he passesstatsCtx to the websocket read that gives us two paths to cancellation that could occur at two different times.

I think a cancellation of the parent context would propogate tostatsCtx but not the other way around since a time-out is not always indicative of cancellation of the parent ctx.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting. The two paths of cancellation is definitely a valid point. Especially considering you'd want a much shorter timeout for the initialDial

I'd say that makes me in favor of something similar to what Colin is suggesting where the WebSocket opener just returns some watcher structure that holds additional methods for listening that are bounded by a different context.

}

// WaitForEnvironmentReady watches the environment update websocket and waits for the "done" message type before returning.
func (c Client) WaitForEnvironmentReady(ctx context.Context, envID string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also return a channel that getsEnvUpdates and a higher-level wrapper would wait for"done".

m := stats{}
err = wsjson.Read(ctx, conn, &m)
if err != nil {
return fmt.Errorf("read ws json msg: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

xerrors to be consistent.

fuskovic reacted with thumbs up emoji
@coadler
Copy link
Contributor

+1 for the standardization of pointer vs value returns. I lean towards returning pointers personally.


// DeleteEnvironment deletes the environment.
func (c Client) DeleteEnvironment(ctx context.Context, envID string) error {
err := c.requestBody(
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick : Is this allocation necessary or can we just return the requestBody invocation?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

good call

Comment on lines 178 to 180
statsCtx, statsCancel := context.WithTimeout(ctx, duration)
defer statsCancel()

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this one@cmoog

I think if he passesstatsCtx to the websocket read that gives us two paths to cancellation that could occur at two different times.

I think a cancellation of the parent context would propogate tostatsCtx but not the other way around since a time-out is not always indicative of cancellation of the parent ctx.

}

// WatchEnvironmentStats watches the environment update websocket for a given duration.
func (c Client) WatchEnvironmentStats(ctx context.Context, envID string, duration time.Duration) error {
Copy link
Contributor

@fuskovicfuskovicAug 26, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think we could probably return some data-structure here that implementsio.ReadCloser to piggy back on@coadler 's point.

@f0sself0sselforce-pushed thestress-sdk branch 4 times, most recently fromdf519d9 to902ce7bCompareAugust 28, 2020 16:28
@f0ssel
Copy link
ContributorAuthor

Hey@coadler ,@cmoog ,@fuskovic thanks for the feedback on this. I've cut down my changes to a much simpler set and will move more of the business logic into the enterprise repo to keep this cleaner for everyone while keeping the feedback here in mind.

Copy link
Contributor

@cmoogcmoog left a comment

Choose a reason for hiding this comment

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

This works for now given that we're not asking users to consume this SDK and this PR is blocking the stress-test work. That said, I'd like us to hide the underlying*websocket.Conn from our stat streaming/buildlog interactions before we expect users to depend on this package.

Copy link
Contributor

@coadlercoadler left a comment

Choose a reason for hiding this comment

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

+1 what@cmoog said. If we intend for customers to use this, we'll need to write some wrapper around the returned ws conn.

Any specific reason for the departure from returning pointers? The usage seems a bit inconsistent now.

@f0ssel
Copy link
ContributorAuthor

@coadler thanks for the catch, just an oversight, updated to return pointers

@f0ssel
Copy link
ContributorAuthor

@cmoog I agree, I can see us consuming this later similar to how the DialWsep is working currently once the stress testing stuff is in less flux

@f0sself0ssel merged commit0f0160a intomasterAug 28, 2020
@f0sself0ssel deleted the stress-sdk branchAugust 28, 2020 19:38
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@coadlercoadlercoadler approved these changes

@cmoogcmoogcmoog approved these changes

@fuskovicfuskovicfuskovic approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@f0ssel@coadler@cmoog@fuskovic

[8]ページ先頭

©2009-2025 Movatter.jp