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

Stream agent logs remotely #1774

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft

Stream agent logs remotely #1774

wants to merge 30 commits into from

Conversation

jan-law
Copy link
Contributor

@jan-law jan-law commented Oct 16, 2023

Fixes #1655

Depends on #1642

Example usage: opni debug agent-logs --level=debug --follow <cluster-id>

Copy link
Contributor Author

@jan-law jan-law left a comment

Choose a reason for hiding this comment

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

Added two questions about writing plugin loggers to log files. Once those are resolved, this PR is ready for review

pkg/logger/logger.go Outdated Show resolved Hide resolved
@jan-law jan-law marked this pull request as ready for review October 16, 2023 20:33
@jan-law jan-law requested a review from kralicky October 16, 2023 20:33
@jan-law jan-law force-pushed the agent-logs branch 6 times, most recently from 82e1abf to b5c314a Compare October 18, 2023 20:00
@jan-law
Copy link
Contributor Author

jan-law commented Oct 18, 2023

When running the opni debug agent-logs in my k3s cluster, I get an Unrecognized remote plugin message for one of the log messages. Do you know where this log message is created?

Tried searching here and couldn't find it: https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-go-contrib+%22Tracer+created%22&type=code

2023 Oct 18 20:51:14 ERROR agent.pluginloader plugins/loader.go:156 failed to load plugin plugin=github.com/rancher/opni/plugins/logging err=Unrecognized remote plugin message: 2023 Oct 18 20:51:14 DEBUG global/internal_logging.go:53 Tracer created logger=tracing name=go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc version=0.42.0 schemaURL=""
This usually means
  the plugin was not compiled for this architecture,
  the plugin is missing dynamic-link libraries necessary to run,
  the plugin is not executable by this process due to file permissions, or
  the plugin failed to negotiate the initial go-plugin protocol handshake

Additional notes about plugin:
  Path: /var/lib/opni-agent/plugins/plugin_logging
  Mode: -rwxr-xr-x
  Owner: 0 [root] (current: 0 [root])
  Group: 0 [root] (current: 0 [root])
  ELF architecture: EM_X86_64 (current architecture: amd64)

@kralicky
Copy link
Member

@jan-law that message is generated by the go-plugin library when writing to a logger that isn't set up to forward its log messages to the host process.

@jan-law
Copy link
Contributor Author

jan-law commented Oct 20, 2023

that message is generated by the go-plugin library when writing to a logger that isn't set up to forward its log messages to the host process.

Update - it seems that go-plugin expects logs to be sent to stderr instead of stdout. This issue affects the slog branch too. Making a fix for it now.

@jan-law jan-law force-pushed the agent-logs branch 2 times, most recently from 7079f5d to eca919f Compare October 23, 2023 19:41
DefaultTimeFormat = "2006 Jan 02 15:04:05"
errKey = "err"
)

var logSampler = &sampler{}

func init() {
logFs = afero.NewMemMapFs()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plugin logs do not appear in the debug agent-logs output. Do the plugins share the same logFs here if they are different processes?

Copy link
Member

Choose a reason for hiding this comment

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

No, they will be separate. The plugins should be sending their logs to the host process though, maybe that needs some refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although I wasn't able to stream the logs over SyncStderr, the Logger in the ClientConfig can forward the log messages to a writer, where I can log them with a logger on the host side.

Logger: hclog.New(&hclog.LoggerOptions{
			Level:  hclog.Debug,
			Output: logger.PluginFileWriter,
		}),

Go-plugin can't directly forward protobuf message bytes unfortunately, as it's hardcoded to cast all non-hclog output to a string: https://github.com/hashicorp/go-plugin/blob/017b758bf4d495212a55db3de61b2d95ab104e53/client.go#L1155

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The forwarded logs look like this. What do you think of the formatting?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Log streaming is working with the forked go-plugin patch in my k3s cluster. I replaced the hclog forwarding logger with io.Copy(c.config.Stderr, r). I'm working on fixing the test env output because the plugins are logging the gprc bytes to stderr

@jan-law
Copy link
Contributor Author

jan-law commented Nov 6, 2023

Depends on alexandreLamarre/go-plugin#2

@jan-law jan-law force-pushed the agent-logs branch 2 times, most recently from 22a45f0 to 79f58fb Compare November 6, 2023 18:13
@jan-law jan-law marked this pull request as draft November 9, 2023 21:43
@jan-law
Copy link
Contributor Author

jan-law commented Nov 9, 2023

Setting this PR back to draft mode while I work on the plugin loggers for the standalone test env

pkg/opni/commands/debug.go Show resolved Hide resolved
pkg/opni/commands/debug.go Show resolved Hide resolved
@jan-law jan-law force-pushed the agent-logs branch 2 times, most recently from 60922f0 to bf3716e Compare November 14, 2023 19:18
@jan-law jan-law force-pushed the agent-logs branch 3 times, most recently from b2397dd to 9b25384 Compare November 27, 2023 22:07
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.

Management API to stream agent logs
2 participants