master
go 54 lines 1.22 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package metrix
4
5 // ReadOption controls reader visibility mode.
6 type ReadOption interface {
7 applyRead(*readConfig)
8 }
9
10 type readOptionFunc func(*readConfig)
11
12 func (f readOptionFunc) applyRead(cfg *readConfig) {
13 f(cfg)
14 }
15
16 type readConfig struct {
17 raw bool
18 flatten bool
19 hostScopeKey string
20 }
21
22 func resolveReadConfig(opts ...ReadOption) readConfig {
23 cfg := readConfig{}
24 for _, opt := range opts {
25 if opt != nil {
26 opt.applyRead(&cfg)
27 }
28 }
29 return cfg
30 }
31
32 // ReadRaw enables raw committed-series visibility mode for Read().
33 // Without this option, Read() applies freshness filtering.
34 func ReadRaw() ReadOption {
35 return readOptionFunc(func(cfg *readConfig) {
36 cfg.raw = true
37 })
38 }
39
40 // ReadFlatten enables flattened scalar-series view mode for Read().
41 // Without this option, Read() returns canonical typed-family view.
42 func ReadFlatten() ReadOption {
43 return readOptionFunc(func(cfg *readConfig) {
44 cfg.flatten = true
45 })
46 }
47
48 // ReadHostScope filters the reader to one host scope. The empty key is the
49 // default scope and matches unscoped writes.
50 func ReadHostScope(scopeKey string) ReadOption {
51 return readOptionFunc(func(cfg *readConfig) {
52 cfg.hostScopeKey = scopeKey
53 })
54 }