-
Notifications
You must be signed in to change notification settings - Fork 300
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
Add current-job api #1943
Add current-job api #1943
Conversation
d948e81
to
0ea0a67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments for you!
37a923c
to
52a6c01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! I wrote some more comments for you...
4d63043
to
47be827
Compare
d6a4098
to
2484b4d
Compare
@@ -44,7 +44,7 @@ type BootstrapTester struct { | |||
} | |||
|
|||
func NewBootstrapTester() (*BootstrapTester, error) { | |||
homeDir, err := os.MkdirTemp("", "home") | |||
homeDir, err := os.MkdirTemp("/tmp", "home") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a comment mentioning the Linux-path-length-for-Unix-sockets problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎉 🎉 🥳 🎊 🪩 🍕
A bunch of remaining comments are minor nits, I leave it up to you whether to apply, raise a follow-up, or ignore 🥺
|
||
resp := EnvGetResponse{Env: normalizedEnv} | ||
w.WriteHeader(http.StatusOK) | ||
json.NewEncoder(w).Encode(resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Something to think about] If this did return an error, is that worth logging?
go func() { | ||
_ = s.httpSvr.Serve(l) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] If the error is being dropped here (which is fine) then why not go s.httpSvr.Serve(l)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a func returns an err that i'm not tracking, i much prefer to have _ = mightFail()
, as it makes my intentions clear - it shows that i know that this function might return an error, but that i explicitly don't care. happy to change either way, but it's a readability thing that i like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, and tend to agree that _ =
to denote deliberately ignored errors is nice. I'm less used to it.
Though I think http.Server.Serve
is a bit unusual in that it always returns a non-nil error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's true, i hadn't realised that... i think we're probably still fine to ignore it though, unless you disagree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring it is fine, with either syntax.
@@ -1,3 +1,5 @@ | |||
*.DS_STORE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a .gitignorefmt
. I want to argue with this being at this spot in the file and in all caps, but it also isn't wrong?
dc3ce8a
to
8dacf98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I have some early comments I want to get in.
jobapi/server_test.go
Outdated
t.Fatalf("os.Stat(%q) error = %v", srv.SocketPath, err) | ||
} | ||
|
||
isSocket := info.Mode()&os.ModeSocket != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just discovered golang/go#33357, so this check might need skipping on Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble even calling os.Stat
on the socket on Windows. But connecting to it is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what I ended up with in the client:
Lines 51 to 69 in 3f9c89d
// Check the socket path exists and is a socket. | |
// Note that os.ModeSocket might not be set on Windows. | |
// (https://github.com/golang/go/issues/33357) | |
if runtime.GOOS != "windows" { | |
fi, err := os.Stat(sock) | |
if err != nil { | |
return nil, fmt.Errorf("stat socket: %w", err) | |
} | |
if fi.Mode()&os.ModeSocket == 0 { | |
return nil, fmt.Errorf("%q is not a socket", sock) | |
} | |
} | |
// Try to connect to the socket. | |
test, err := net.Dial("unix", sock) | |
if err != nil { | |
return nil, fmt.Errorf("socket test connection: %w", err) | |
} | |
test.Close() |
38d241b
to
2ca3dc9
Compare
This is an API that allows the currently-running job to observe and mutate its own state in the form of environment variables. It's exposed via a Unix Domain Socket on supported OSes, and unsupported ones (Windows prior to build 17063) may not use it
Co-authored-by: Josh Deprez <[email protected]>
Co-authored-by: Josh Deprez <[email protected]>
silly me, filepath.Join is OS-aware, but path.Join just puts in a slash! how could i have been so boneheaded!
This PR: Exposes an API through the agent's job executor (aka "the bootstrap") that allows running jobs to mutate or introspect their own state.
This API currently exposes three endpoints:
GET /api/current-job/v0/env
to get the environment of the currently running jobPATCH /api/current-job/v0/env
to update the job's environmentDELETE /api/current-job/v0/env
to remove certain keys from the job's environmentOn unix machines, this API is exposed via a unix domain socket, and on windows, TBD.
Still to do:
Figure out how to serve thewe're going to do this in a separate PRjobapi.Server
on windows (probably a normal TCP port or something? UDSes are available on recent builds of windows, but we don't want to have to replay on that)jobapi.Server
jobapi.Server
from the job executor + do some manual testing that it looks all goodCreate aWe're also going to do this in a separate PR (and potentially later on)jobapi.Client
thingy to allow other bits of the agent (and potentially other golang projects 👀) to use this API