Skip to content

Add metrics exporter#184

Open
TimEvens wants to merge 8 commits into
draft-18from
metrics-export
Open

Add metrics exporter#184
TimEvens wants to merge 8 commits into
draft-18from
metrics-export

Conversation

@TimEvens

@TimEvens TimEvens commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Export metrics via publish track using namespace <metrics namespace>/<relay id> and name <type such as connection, subscribe, publish>

Metrics will be emitted every time the callback is called with metrics.

Adapters/consumers can consume metrics by using SUBSCRIBE_TRACKS on the metrics namespace.

Instead of using a JSON lib with another deps, this has a small implementation to format the metrics in json format.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8dbd077325

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/metrics_publisher.cc Outdated
Comment on lines +421 to +422
auto handler = CreateTrackHandler(type);
session_.PublishTrack(connection_handle, handler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate metrics tracks on active metrics subscribers

When any metrics sample is processed, this path unconditionally opens the three metrics publish tracks on that connection, even for clients that never sent SUBSCRIBE_TRACKS for the metrics namespace. In deployments with normal media-only clients, their first metrics callback now consumes request IDs and sends unsolicited PUBLISH control messages for metrics tracks; wire this into the existing metrics namespace subscription flow instead of creating tracks for every connection.

Useful? React with 👍 / 👎.

Comment thread src/metrics_publisher.cc Outdated
Comment on lines +432 to +433
std::lock_guard<std::mutex> lock(tracks_mutex_);
tracks_by_connection_.try_emplace(connection_handle, std::move(tracks));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck connection liveness before storing tracks

If a connection closes after the initial tracks_by_connection_ check but before this insertion, RemoveConnection() can erase it and then this worker thread stores handlers for a closed connection. Later PublishSample() iterates every stored handler, so subsequent metrics keep trying to publish to this stale target until process exit; revalidate the connection under the mutex before try_emplace or keep an active-connection marker.

Useful? React with 👍 / 👎.

Comment thread src/client_manager.cc
return false;
}

it->second->ObjectReceived(object_headers, data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be dispatched across from the metrics thread (which I think it's being called from in the metrics case) to the notifier thread either here or by the caller. Otherwise it could race with internal state that assumes ObjectReceived is only ever called from the notifier thread.

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