Skip to content

feat: add sum aggregator to support summing numeric values - #82

Merged
kazeburo merged 1 commit into
mainfrom
feat/sum-aggregator
Oct 12, 2026
Merged

kazeburo merged 1 commit into
mainfrom
feat/sum-aggregator

Conversation

@kazeburo

@kazeburo kazeburo commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests, Documentation


Description

  • Add sum aggregation for numeric JSON values.

  • Apply numeric modifiers and duration-based output scaling.

  • Test accumulation alongside existing aggregators.

  • Document usage and supported modifiers.


Diagram Walkthrough

flowchart LR
  input["Numeric JSON value"]
  parse["Parse as float"]
  total["Accumulate sum"]
  output["Apply modifiers and duration scaling"]
  input -- "extract" --> parse
  parse -- "add" --> total
  total -- "emit metric" --> output
Loading

File Walkthrough

Relevant files
Enhancement
main.go
Advertise sum aggregation in command-line help                     

cmd/mackerel-plugin-jsonl/main.go

  • List sum among supported CLI aggregators.
+1/-1     
percentile.go
Recognize sum in aggregator option parsing                             

cmd/mackerel-plugin-jsonl/percentile.go

  • Accept sum as an aggregator name.
+1/-1     
reader.go
Accumulate and emit duration-scaled sum metrics                   

cmd/mackerel-plugin-jsonl/reader.go

  • Accumulate parsed numeric values in a sum field.
  • Restrict string modifiers and initializers for sum.
  • Apply numeric modifiers and duration scaling when emitting sum
    metrics.
+18/-2   
Tests
parser_test.go
Test sum accumulation with existing aggregators                   

cmd/mackerel-plugin-jsonl/parser_test.go

  • Parse 100 records and verify their numeric sum.
  • Check count, grouping, and percentile behavior alongside sum.
+28/-14 
Documentation
README.md
Document sum aggregation and modifier compatibility           

README.md

  • Document sum usage and an example metric.
  • Include sum in multiply support and clarify modifier restrictions.
+6/-5     

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Comparison

Base: main
PR: feat/sum-aggregator

BenchmarkMainParse results
goos: linux
goarch: amd64
pkg: github.com/monitoring-forge/mackerel-plugin-jsonl/cmd/mackerel-plugin-jsonl
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
                             │ base-bench.txt │            pr-bench.txt            │
                             │     sec/op     │   sec/op     vs base               │
MainParse_jsonl-4                30.46m ± 19%   32.24m ± 1%  +5.84% (p=0.023 n=10)
MainParse_jsonl_eachkey-4        37.86m ±  1%   38.47m ± 1%  +1.61% (p=0.000 n=10)
MainParse_parse_and_output-4     31.76m ±  1%   33.88m ± 1%  +6.68% (p=0.000 n=10)
geomean                          33.21m         34.76m       +4.69%

                             │ base-bench.txt │            pr-bench.txt             │
                             │      B/op      │     B/op      vs base               │
MainParse_jsonl-4                4.642Mi ± 0%   4.642Mi ± 0%       ~ (p=0.448 n=10)
MainParse_jsonl_eachkey-4        4.642Mi ± 0%   4.642Mi ± 0%  +0.00% (p=0.000 n=10)
MainParse_parse_and_output-4     5.412Mi ± 0%   5.412Mi ± 0%  +0.00% (p=0.000 n=10)
geomean                          4.886Mi        4.886Mi       +0.00%

                             │ base-bench.txt │            pr-bench.txt            │
                             │   allocs/op    │  allocs/op   vs base               │
MainParse_jsonl-4                 100.4k ± 0%   100.4k ± 0%       ~ (p=0.598 n=10)
MainParse_jsonl_eachkey-4         100.4k ± 0%   100.4k ± 0%       ~ (p=0.474 n=10)
MainParse_parse_and_output-4      100.5k ± 0%   100.5k ± 0%       ~ (p=0.635 n=10)
geomean                           100.4k        100.4k       -0.00%

@kazeburo
kazeburo merged commit 6dd960a into main Oct 12, 2026
5 checks passed
@kazeburo
kazeburo deleted the feat/sum-aggregator branch October 12, 2026 06:20
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant