Skip to content

Commit cc17db9

Browse files
committed
Add counters draft client API
Signed-off-by: Tomasz Pietrek <[email protected]>
1 parent f748ac7 commit cc17db9

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

adr/ADR-49.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,38 @@ In this case a dedicated light weight Counter client to begin with would be adde
226226
> This is just an idea at present, the client will be fleshed out later in the development cycle.
227227
228228
```go
229-
// Creates a new counter abstraction bound to a Stream
230-
func NewCounter(stream jetstream.Stream) (Counter, error)
231-
232-
// Parses a messages received from a consumer into a counter entry
233-
func ParseMessage(msg jetstream.Msg) (Entry, error)
234-
235-
// Entry holds helpers for parsing the values in counters
236-
type Entry interface {
237-
// Value parses the value as a big.Int
238-
Value() (big.Int, error)
239-
240-
// The messages that contributed to the Value
241-
Messages() []jetstream.Msg
242-
}
229+
``package counters
230+
231+
import "math/big"
243232

244-
// Increments and loads
245233
type Counter interface {
246-
// Increments a counter by delta
247-
func Increment(subject string, value int64) (Entry, error)
248-
249-
// Loads the value from the stream subject, options to supply a specific seq/time for example
250-
func Load(subject string, opts ...LoadOption) (Entry, error)
251-
252-
// Loads a group of subjects from the same stream using a direct batch get, performs the
253-
// calculation to combine these numbers client side
254-
func LoadMulti(subjects []string, opts ...LoadOptions) ([]Entry, error)
234+
/// Adds or subtracts a value from the counter, returning the new value.
235+
Add(counter string, value big.Int) (big.Int, error)
236+
/// Load retrieves the current value of the counter, using direct get with no headers.
237+
Load(counter string) (big.Int, error)
238+
/// LoadMultiple retrieves the current values of multiple counters, using direct get with no headers.
239+
/// It allows using wildcards in the counter names.
240+
LoadMultiple(counters []string) (Values, error)
241+
/// Get retrieves the current value of a counter, including its sources.
242+
GetEntry(counter string) (Entry, error)
243+
/// GetMany retrieves the current values of multiple counters, including their sources.
244+
/// It allows using wildcards in the counter names.
245+
GetEntries(counters []string) (Entries, error)
255246
}
256-
```
247+
248+
type Entry struct {
249+
Value big.Int
250+
// TODO: maybe there is a prettier way to represent the sources.
251+
// For now, we're using the server representation.
252+
Sources map[string]map[string]string
253+
254+
}
255+
256+
// Allows iterating over multiple counters values.
257+
type Values struct {}
258+
259+
260+
// Allows iterating over multiple counter Entries.
261+
type Entries struct {}
262+
263+
`

0 commit comments

Comments
 (0)