Skip to content

Metrics: add ext/aux meters#29836

Merged
andig merged 5 commits into
masterfrom
feat/extaux_metrics
May 15, 2026
Merged

Metrics: add ext/aux meters#29836
andig merged 5 commits into
masterfrom
feat/extaux_metrics

Conversation

@naltatis
Copy link
Copy Markdown
Member

@naltatis naltatis commented May 12, 2026

refs #29144

Adds per-meter metrics.Collector for ext and aux meters, mirroring the grid/battery/pv pattern.

Todo

@naltatis naltatis added the enhancement New feature or request label May 12, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The extEnergy and auxEnergy maps are populated using ref in Boot, but addMeterEnergy looks up collectors by dev.Config().Name, which can diverge from ref; consider using the same key (ref or Config().Ref) consistently for both map population and lookup.
  • In addMeterEnergy, the function assumes meters and mm have matching lengths when indexing by i; if this ever changes upstream, a bounds panic is possible, so it may be safer to guard on the minimum length or explicitly validate the sizes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `extEnergy` and `auxEnergy` maps are populated using `ref` in `Boot`, but `addMeterEnergy` looks up collectors by `dev.Config().Name`, which can diverge from `ref`; consider using the same key (`ref` or `Config().Ref`) consistently for both map population and lookup.
- In `addMeterEnergy`, the function assumes `meters` and `mm` have matching lengths when indexing by `i`; if this ever changes upstream, a bounds panic is possible, so it may be safer to guard on the minimum length or explicitly validate the sizes.

## Individual Comments

### Comment 1
<location path="core/site.go" line_range="739" />
<code_context>
+// addMeterEnergy persists per-meter energy (positive power = import).
+func (site *Site) addMeterEnergy(key string, meters []config.Device[api.Meter], collectors map[string]*metrics.Collector, mm []types.Measurement) {
+	for i, dev := range meters {
+		c, ok := collectors[dev.Config().Name]
+		if !ok {
+			continue
</code_context>
<issue_to_address>
**issue (bug_risk):** Collector map is keyed by meter ref, but lookup uses `Config().Name`, which may not match.

`extEnergy`/`auxEnergy` are populated as `site.extEnergy[ref] = me` / `site.auxEnergy[ref] = me`, with the maps documented as keyed by meter ref. Here, the lookup uses `collectors[dev.Config().Name]`. If `ref``Config().Name`, the collector won’t be found and energy won’t be persisted. Please align the lookup key with the map key (e.g. use `ref` or whatever is used when populating the map).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread core/site.go Outdated
@naltatis naltatis mentioned this pull request May 12, 2026
6 tasks
Comment thread core/metrics/collector.go Outdated
Comment thread core/site.go Outdated
@andig andig added the infrastructure Basic functionality label May 12, 2026
@naltatis
Copy link
Copy Markdown
Member Author

Collected values look fine.

Comment thread core/site.go
Comment thread core/site.go
@andig
Copy link
Copy Markdown
Member

andig commented May 15, 2026

@copilot resolve the merge conflicts in this pull request

@andig andig enabled auto-merge (squash) May 15, 2026 14:39
Co-authored-by: andig <184815+andig@users.noreply.github.com>
auto-merge was automatically disabled May 15, 2026 14:44

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts are resolved in 87629c2 by merging origin/master and reconciling core/site.go and core/metrics/collector.go.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 192.168.1.1
    • Triggering command: /tmp/go-build738721479/b1500/service.test /tmp/go-build738721479/b1500/service.test -test.testlogfile=/tmp/go-build738721479/b1500/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build738721479/b1435/_pkg_.a 3.2/prometheus/p-errorsas 3.2/prometheus/p-ifaceassert ux-amd64/pkg/tool/linux_amd64/vet -errorsas ctor m ux-amd64/pkg/too-buildtags -o ux@v0.1.2/addr.g-errorsas ux@v0.1.2/const.-ifaceassert ux-amd64/pkg/tool/linux_amd64/vet -p bber mpile ux-amd64/pkg/too-buildtags (packet block)
  • 224.0.0.251
    • Triggering command: REDACTED, pid is -1 (packet block)
  • api.awattar.at
    • Triggering command: /tmp/go-build738721479/b1451/tariff.test /tmp/go-build738721479/b1451/tariff.test -test.testlogfile=/tmp/go-build738721479/b1451/testlog.txt -test.paniconexit0 -test.timeout=10m0s om/m�� /v2@v2.14.0/inte-errorsas t ux-amd64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert mpile ux-amd64/pkg/too-buildtags -ato�� r/shoutrrr@v0.14-errorsas r/shoutrrr@v0.14-ifaceassert ux-amd64/pkg/tool/linux_amd64/vet -errorsas rnal/write mpile ux-amd64/pkg/too-trimpath (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of andig May 15, 2026 14:48
Copilot AI requested a review from andig May 15, 2026 14:48
@andig andig enabled auto-merge (squash) May 15, 2026 15:01
@andig andig changed the title Ext/Aux meters: track energy metrics Metrics: add ext/aux meters May 15, 2026
Drop separate site.pvEnergy map and site.fcstEnergy field; route PV and
solar forecast collectors through the shared site.collectors map. Also
formats NewSite() struct literal to satisfy gofmt/gci (fixes Lint and
Clean CI failures).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andig andig merged commit a74982a into master May 15, 2026
6 of 7 checks passed
@andig andig deleted the feat/extaux_metrics branch May 15, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request infrastructure Basic functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants