From cc17db91fc7ceaaaf10a238097da987ba54db3bb Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Fri, 27 Jun 2025 16:06:21 +0200 Subject: [PATCH 1/2] Add counters draft client API Signed-off-by: Tomasz Pietrek --- adr/ADR-49.md | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/adr/ADR-49.md b/adr/ADR-49.md index a52691f2..060819f5 100644 --- a/adr/ADR-49.md +++ b/adr/ADR-49.md @@ -226,31 +226,38 @@ In this case a dedicated light weight Counter client to begin with would be adde > This is just an idea at present, the client will be fleshed out later in the development cycle. ```go -// Creates a new counter abstraction bound to a Stream -func NewCounter(stream jetstream.Stream) (Counter, error) - -// Parses a messages received from a consumer into a counter entry -func ParseMessage(msg jetstream.Msg) (Entry, error) - -// Entry holds helpers for parsing the values in counters -type Entry interface { - // Value parses the value as a big.Int - Value() (big.Int, error) - -// The messages that contributed to the Value - Messages() []jetstream.Msg -} +``package counters + +import "math/big" -// Increments and loads type Counter interface { - // Increments a counter by delta - func Increment(subject string, value int64) (Entry, error) - - // Loads the value from the stream subject, options to supply a specific seq/time for example - func Load(subject string, opts ...LoadOption) (Entry, error) - - // Loads a group of subjects from the same stream using a direct batch get, performs the - // calculation to combine these numbers client side - func LoadMulti(subjects []string, opts ...LoadOptions) ([]Entry, error) + /// Adds or subtracts a value from the counter, returning the new value. + Add(counter string, value big.Int) (big.Int, error) + /// Load retrieves the current value of the counter, using direct get with no headers. + Load(counter string) (big.Int, error) + /// LoadMultiple retrieves the current values of multiple counters, using direct get with no headers. + /// It allows using wildcards in the counter names. + LoadMultiple(counters []string) (Values, error) + /// Get retrieves the current value of a counter, including its sources. + GetEntry(counter string) (Entry, error) + /// GetMany retrieves the current values of multiple counters, including their sources. + /// It allows using wildcards in the counter names. + GetEntries(counters []string) (Entries, error) } -``` + +type Entry struct { + Value big.Int + // TODO: maybe there is a prettier way to represent the sources. + // For now, we're using the server representation. + Sources map[string]map[string]string + +} + +// Allows iterating over multiple counters values. +type Values struct {} + + +// Allows iterating over multiple counter Entries. +type Entries struct {} + +` From 34af214086023e75432d2f786f03c628563ce32b Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Tue, 8 Jul 2025 10:37:07 +0200 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Tomasz Pietrek --- adr/ADR-49.md | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/adr/ADR-49.md b/adr/ADR-49.md index 060819f5..24340127 100644 --- a/adr/ADR-49.md +++ b/adr/ADR-49.md @@ -231,26 +231,25 @@ In this case a dedicated light weight Counter client to begin with would be adde import "math/big" type Counter interface { - /// Adds or subtracts a value from the counter, returning the new value. - Add(counter string, value big.Int) (big.Int, error) - /// Load retrieves the current value of the counter, using direct get with no headers. - Load(counter string) (big.Int, error) - /// LoadMultiple retrieves the current values of multiple counters, using direct get with no headers. - /// It allows using wildcards in the counter names. - LoadMultiple(counters []string) (Values, error) - /// Get retrieves the current value of a counter, including its sources. - GetEntry(counter string) (Entry, error) - /// GetMany retrieves the current values of multiple counters, including their sources. - /// It allows using wildcards in the counter names. - GetEntries(counters []string) (Entries, error) + // Adds or subtracts a value from the counter, returning the new value. + Add(counter string, value big.Int) (big.Int, error) + // Load retrieves the current value of the counter, using direct get with no headers. + Load(counter string) (big.Int, error) + // LoadMultiple retrieves the current values of multiple counters, using direct get with no headers. + // It allows using wildcards in the counter names. + LoadMultiple(counters []string) (Values, error) + // Get retrieves the current value of a counter, including its sources. + GetEntry(counter string) (Entry, error) + // GetMany retrieves the current values of multiple counters, including their sources. + // It allows using wildcards in the counter names. + GetEntries(counters []string) (Entries, error) } type Entry struct { - Value big.Int + Value big.Int // TODO: maybe there is a prettier way to represent the sources. // For now, we're using the server representation. - Sources map[string]map[string]string - + Sources map[string]map[string]string } // Allows iterating over multiple counters values.