Skip to content

feat: add copilot window for stats#338

Open
caalador wants to merge 5 commits into
mainfrom
copilot-metrics-view
Open

feat: add copilot window for stats#338
caalador wants to merge 5 commits into
mainfrom
copilot-metrics-view

Conversation

@caalador

Copy link
Copy Markdown
Collaborator

Add a copilot window to look at
collected stats.

To see window in any mode but play
click on the bar-graph observability
button.

Add a copilot window to look at
collected stats.

To see window in any mode but play
click on the bar-graph observability
button.
@caalador caalador force-pushed the copilot-metrics-view branch from 0327148 to be4bf59 Compare June 12, 2026 09:34
@caalador caalador marked this pull request as ready for review June 23, 2026 07:22
LoggerFactory.getLogger(ObservabilityDevToolsClient.class).warn(
"Could not load observability-kit dev-tools panel code", e);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This duplicates almost verbatim this ensureClientLoaded method:

private static void ensureClientLoaded(UI ui) {
if (ComponentUtil.getData(ui, CLIENT_INIT_KEY) != null) {
return;
}
ComponentUtil.setData(ui, CLIENT_INIT_KEY, Boolean.TRUE);
ClassLoader loader = MetricsCollectorElement.class.getClassLoader();
try (InputStream in = loader.getResourceAsStream(CLIENT_RESOURCE)) {
if (in == null) {
LoggerFactory.getLogger(MetricsCollectorElement.class).warn(
"observability-kit client resource not found: {}",
CLIENT_RESOURCE);
return;
}
String js = StringUtil.removeComments(
new String(in.readAllBytes(), StandardCharsets.UTF_8),
true);
ui.getPage().executeJs(js);
} catch (IOException e) {
LoggerFactory.getLogger(MetricsCollectorElement.class)
.warn("Could not load observability-kit client code", e);
}
}

I suggest to extract e.g. a injectClientResource(UI, key, resource) to avoid duplication.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Extracted to Util for reuse when needed.

Comment on lines +103 to +106
} else if (meter instanceof Counter counter) {
entry.put("count", (long) counter.count());
} else if (meter instanceof FunctionCounter counter) {
entry.put("count", (long) counter.count());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why casting these two counters to long, while DistributionSummary below is kept double?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DistributionSummary.count() actually returns long and not double where as counter and functionCounter return double so they are cast to long to normalize the value to integer for the panel.

Comment on lines +26 to +28
// Per-meter ring buffer of recent trend values, keyed by name+tags. Survives
// panel close/reopen (module scope) so the sparkline keeps its history.
var history = {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to evict history at some point?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The buffers themselves are set to 20 items, but a key is not removed at any point after it has been added. The list is thus persisted for the page lifetime.

Not certain if we need to clean it with the current key amount, but could be something to think about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎Iteration reviews

Development

Successfully merging this pull request may close these issues.

2 participants