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

feat: write agent output to a temporary file#422

Merged
jawnsy merged 3 commits intomainfromjawnsy/ch16783/coder-agent-tee
Sep 2, 2021

Conversation

jawnsy
Copy link
Contributor

@jawnsyjawnsy commentedSep 2, 2021
edited
Loading

How I tested this

Running the agent, the log data is written to a file as well (and truncated/re-created on subsequent starts):

$ go run ./cmd/coder/main.go agent start2021-09-02 01:36:32.847 [INFO]  <agent.go:90>   starting wsnet listener {"coder_access_url": "https://master.cdr.dev"}2021-09-02 01:36:32.848 [INFO]  <listen.go:114> connecting to broker    {"broker_url": "wss://master.cdr.dev/api/private/envagent/listen?service_token=xxx"}2021-09-02 01:36:32.928 [INFO]  <listen.go:136> broker connection established^C2021-09-02 01:36:53.420 [INFO]        <agent.go:96>   closing wsnet listener2021-09-02 01:36:53.421 [INFO]  <listen.go:451> listener closed$ cat /tmp/coder-agent.log 2021-09-02 15:22:25.006 [INFO]  <agent.go:92>   starting wsnet listener {"coder_access_url": "https://master.cdr.dev"}2021-09-02 15:22:25.007 [INFO]  <listen.go:114> connecting to broker    {"broker_url": "wss://master.cdr.dev/api/private/envagent/listen?service_token=xxx"}2021-09-02 15:22:25.098 [INFO]  <listen.go:136> broker connection established2021-09-02 15:22:26.690 [INFO]  <agent.go:98>   closing wsnet listener2021-09-02 15:22:26.690 [INFO]  <listen.go:451> listener closed

If there's a permission error preventing the file frmo being truncated, a log message will be output to stderr (simulated by chowning the file to root):

$ sudo chown root:root /tmp/coder-agent.log $ go run ./cmd/coder/main.go agent start2021-09-02 01:41:21.363 [INFO]  <agent.go:65>   failed to open agent log file   {"error": "open /tmp/coder-agent.log: permission denied"}2021-09-02 01:41:21.365 [INFO]  <agent.go:93>   starting wsnet listener {"coder_access_url": "https://master.cdr.dev"}2021-09-02 01:41:21.365 [INFO]  <listen.go:114> connecting to broker    {"broker_url": "wss://master.cdr.dev/api/private/envagent/listen?service_token=xxx"}2021-09-02 01:41:21.478 [INFO]  <listen.go:136> broker connection established^C2021-09-02 01:41:23.116 [INFO]        <agent.go:99>   closing wsnet listener2021-09-02 01:41:23.116 [INFO]  <listen.go:451> listener closed

@shortcut-integration
Copy link

@jawnsyjawnsy self-assigned thisSep 2, 2021
@coveralls
Copy link

coveralls commentedSep 2, 2021
edited
Loading

Pull Request Test Coverage Report forBuild 1194765666

  • 0 of13(0.0%) changed or added relevant lines in1 file are covered.
  • 2 unchanged lines in1 file lost coverage.
  • Overall coverage decreased (-0.04%) to47.954%

Changes Missing CoverageCovered LinesChanged/Added Lines%
internal/cmd/agent.go0130.0%
Files with Coverage ReductionNew Missed Lines%
wsnet/dial.go278.34%
TotalsCoverage Status
Change from baseBuild 1163231010:-0.04%
Covered Lines:2789
Relevant Lines:5816

💛 -Coveralls

@jawnsyjawnsy marked this pull request as ready for reviewSeptember 2, 2021 01:44
sloghuman.Sink(os.Stderr),
}

file, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-agent.log"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

it didn't seem like the file we write needs to be hidden, so I made it a not-dotfile

Copy link
Member

Choose a reason for hiding this comment

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

Should be consistent for the other log files in that case

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Which other log files do we have? I think just a code-server one right?

Copy link
Member

Choose a reason for hiding this comment

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

code-server and envagent, they're in environment_stages.go


file, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-agent.log"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err == nil && file != nil {
sinks = append(sinks, slogjson.Sink(file))
Copy link
Member

Choose a reason for hiding this comment

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

slogjson is very hard to read, and we don't have automated ingestion of this log file into stackdriver so I'd rather stick with sloghuman for now. We can change this later with no consequences

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

We don't have tools for consuming slogjson output and converting to sloghuman output? The slogjson output seems to have more info (e.g. full paths to files) and being machine-readable does seem potentially useful.

I don't have strong feelings about it though, I'll change to sloghuman 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's the only difference between them, they have the same details otherwise. coder-cli doesn't have many files so I'm not too worried about not being able to find the files due to conflicts

@jawnsyjawnsy merged commit6389faf intomainSep 2, 2021
@jawnsyjawnsy deleted the jawnsy/ch16783/coder-agent-tee branchSeptember 2, 2021 16:04

log := slog.Make(sinks...).Leveled(slog.LevelDebug)
if err != nil {
log.Info(ctx, "failed to open agent log file", slog.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be anerror log?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

maybe, but I don't expect it to happen for coder workspaces and everything would be logged to our console anyways

coadler reacted with thumbs up emoji
deansheather pushed a commit that referenced this pull requestSep 8, 2021
deansheather pushed a commit that referenced this pull requestSep 13, 2021
(cherry picked from commit6389faf)(cherry picked from commit45f60ba)
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@coadlercoadlercoadler left review comments

@deansheatherdeansheatherdeansheather approved these changes

Assignees

@jawnsyjawnsy

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@jawnsy@coveralls@coadler@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp