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

Add live graph backend (merge to feature branch) #2645

Open
wants to merge 11 commits into
base: alloy-live-graph
Choose a base branch
from

Conversation

wildum
Copy link
Contributor

@wildum wildum commented Feb 7, 2025

PR Description

This is the backend part of the new live graph.

The approach is similar to live debugging, except that it adds the callback to all components in the given module.

The live debugging feed is now a struct that contains data needed to build the new graph. Because the data string is not needed for the graph, it's passed around as a function. This way we can use the same struct for the live debugging and the live graph with limited performance overhead.

Which issue(s) this PR fixes

Fixes #2608

Notes to the Reviewer

This was tested manually via curl:

  • curl -N http://localhost:12345/api/v0/web/graph to get the data from all components at the root
  • curl -N http://localhost:12345/api/v0/web/graph/{moduleID} to get data from a particular module

PR Checklist

  • [na] CHANGELOG.md updated (will be done in the feature branch)
  • [na] Documentation added (will be done in another branch to the feature branch)
  • Tests updated
  • [na] Config converters updated

@wildum wildum requested a review from a team as a code owner February 7, 2025 11:07
Copy link
Contributor

@thampiotr thampiotr left a comment

Choose a reason for hiding this comment

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

Looking good! some comments, but nothing big

@wildum wildum force-pushed the live-graph-backend branch from a79c730 to 0dd571d Compare February 12, 2025 14:38
Copy link
Contributor

@thampiotr thampiotr left a comment

Choose a reason for hiding this comment

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

Looks much, much cleaner without the callbacks to LiveDebugging(...) function from the service. Few more comments, but we're almost there!

"go.opentelemetry.io/collector/pdata/plog"
)

type LogsInterceptorFunc func(context.Context, plog.Logs) error
Copy link
Contributor

Choose a reason for hiding this comment

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

For all the 3 telemetry signals, can we use Go generics to simplify the code here? Seems like the variation would be only really on plogs.Logs and otelconsumer.Logs types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that works for plogs.Logs but I don't think that we can use a generic type for otelconsumers.Logs because we call ConsumeLogs with it. That means we will still need an interceptor type for each telemetry signal and each will still have its corresponding ConsumeMetrics|ConsumeLogs|ConsumeTraces func

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Maybe that could be avoided with a func but if not, then we'll need to live with this duplication :(

Copy link
Contributor Author

@wildum wildum Feb 20, 2025

Choose a reason for hiding this comment

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

I couldn't find a way to reduce the duplication while keeping the complexity of the code low. Having a bit of duplication for Otel (whether it's in the Otel col project or in Alloy) in the logic between metrics/logs/traces seems to be common. (see the fanout consumer for example). Maybe we should keep it simple and follow the same pattern with a bit of duplication?

return ids
}

func PublishLogsIfActive(debugDataPublisher livedebugging.DebugDataPublisher, componentID string, ld plog.Logs, nextLogs []otelcol.Consumer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think nextLogs needs to be otelcol.Consumer, you only ever use them to extract component ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True but it's quite handy for the components because it's easy to provide.

Would you prefer that I change it to:
PublishLogsIfActive(debugDataPublisher livedebugging.DebugDataPublisher, componentID string, ld plog.Logs, componentIDs []string)
and that I export the extractIDs function?

Or do you have a different idea in mind? I'd like to keep the code as little intrusive as possible in the components

@wildum wildum requested a review from thampiotr February 20, 2025 13:46
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.

2 participants