Skip to content

feat: send logs using agent api v2 if available #264

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

Merged
merged 8 commits into from
Jul 5, 2024
Merged

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jul 4, 2024

Closes #260

  • Removes manually vendored codersdk, we're back on the real deal now
  • Moves logging setup to package internal/eblog
  • Modifies logging to use new agent api v2 methods, falling back to PatchLogs
  • Adds ENVBUILDER_VERBOSE

Tested manually against Coder version 2.8.0, 2.9.0, and 2.13.0.

@johnstcn johnstcn self-assigned this Jul 4, 2024
@johnstcn johnstcn changed the title feat!: use agentsdk.LogSender instead of deprecated method, remove ma… feat!: send logs using agent api v2 Jul 4, 2024
@johnstcn johnstcn force-pushed the cj/agentsdk-logs branch from e629778 to 9a0f335 Compare July 4, 2024 14:01
"github.com/stretchr/testify/require"
)

func Test_sendLogs(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's no longer easy to test this via integration without standing up an entire Coder instance, so removed this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an integration test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not yet. I think this could be a good candidate for a follow-up, but it would mean we need to:

  • Stand up an in-memory Coder instance
  • Create an envbuilder template (we currently keep envbuilder templates in coder/coder)
  • Assert the logs get sent to Coder

It would be fairly heavyweight all in all. What I'd really like is a more lightweight fluentd-like utility that just consumes stdin and forwards to a Coder instance.

@johnstcn johnstcn marked this pull request as ready for review July 4, 2024 14:06
// coderURL and authenticates using token. It then establishes a
// dRPC connection to the Agent API and begins sending logs.
// The returned function is used to block until all logs are sent.
func Coder(ctx context.Context, coderURL *url.URL, token string) (LogFunc, func(), error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

To remove the possibility of this breaking older users, I can check the Coder version and conditionally return a different implementation that uses the old deprecated endpoint. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

We can technically break as we are bumping a major version.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up adding support for backward compatibility based on a similar commit in envbox.

@johnstcn johnstcn changed the title feat!: send logs using agent api v2 feat: send logs using agent api v2 if available Jul 4, 2024
Comment on lines -9 to +10
-e GIT_URL=https://github.com/denoland/deno \
-e INIT_SCRIPT="bash" \
-e ENVBUILDER_GIT_URL=https://github.com/denoland/deno \
-e ENVBUILDER_INIT_SCRIPT="bash" \
Copy link
Member Author

Choose a reason for hiding this comment

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

review: drive-by

require (
cdr.dev/slog v1.6.2-0.20240126064726-20367d4aede6
github.com/GoogleContainerTools/kaniko v1.9.2
github.com/breml/rootcerts v0.2.10
github.com/chainguard-dev/git-urls v1.0.2
github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352
Copy link
Member Author

Choose a reason for hiding this comment

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

this version includes ConnectRPC20 and LogDest

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that it still shows v2.10.1.

Copy link
Member Author

@johnstcn johnstcn Jul 5, 2024

Choose a reason for hiding this comment

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

Yeah I noticed that too, I think it's related to the last tag on main:

git tag --merged main | sort -V | tail -1
v2.10.0

After that, we started using branches.

Copy link
Contributor

Choose a reason for hiding this comment

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

Except in go.mod it's v2.10.1?

Copy link
Member Author

Choose a reason for hiding this comment

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

All I care about is that the commit is present 🤷

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Mostly nit picks

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, minor points

require (
cdr.dev/slog v1.6.2-0.20240126064726-20367d4aede6
github.com/GoogleContainerTools/kaniko v1.9.2
github.com/breml/rootcerts v0.2.10
github.com/chainguard-dev/git-urls v1.0.2
github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that it still shows v2.10.1.

Comment on lines +22 to +23
rpcConnectTimeout = 10 * time.Second
logSendGracePeriod = 10 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I wonder if these should be configurable; at least the timeout feels like it should be.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave this as a follow up, we may not end up needing an extra knob.

"github.com/stretchr/testify/require"
)

func Test_sendLogs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an integration test for this?

@johnstcn johnstcn merged commit 5be0611 into main Jul 5, 2024
4 checks passed
@johnstcn johnstcn deleted the cj/agentsdk-logs branch July 5, 2024 10:33
johnstcn added a commit that referenced this pull request Jul 5, 2024
Closes #260

- Removes manually vendored codersdk, we're back on the real deal now
- Moves logging setup to package internal/eblog
- Modifies logging to use new agent api v2 methods, falling back to PatchLogs
- Adds ENVBUILDER_VERBOSE

Tested manually against Coder version 2.8.0, 2.9.0, and 2.13.0.

(cherry picked from commit 5be0611)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop using deprecated codersdk.LogsSender function
4 participants