Skip to content

Commit d2dfc12

Browse files
authored
feat: add common point option (#18)
1 parent 480189b commit d2dfc12

4 files changed

Lines changed: 30 additions & 19 deletions

File tree

diskcache/diskcache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ func (c *DiskCache) String() string {
104104
c.rwlock.Lock()
105105
defer c.rwlock.Unlock()
106106

107+
// nolint: lll
107108
// if there too many files(>10), only print file count
108109
if n := len(c.dataFiles); n > 10 {
109110
return fmt.Sprintf("%s/[size: %d][fallback: %v][nosync: %v][nopos: %v][nolock: %v][files: %d][maxDataSize: %d][batchSize: %d][capacity: %d][dataFiles: %d]",
110111
c.path, c.size, c.noFallbackOnError, c.noSync, c.noPos, c.noLock, len(c.dataFiles), c.maxDataSize, c.batchSize, c.capacity, n,
111112
)
112113
} else {
114+
// nolint: lll
113115
return fmt.Sprintf("%s/[size: %d][fallback: %v][nosync: %v][nopos: %v][nolock: %v][files: %d][maxDataSize: %d][batchSize: %d][capacity: %d][dataFiles: %v]",
114116
c.path, c.size, c.noFallbackOnError, c.noSync, c.noLock, c.noPos, len(c.dataFiles), c.maxDataSize, c.batchSize, c.capacity, c.dataFiles,
115117
)

point/category_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ func TestURL(t *testing.T) {
2525
{c: "/v1/write/rum", expect: RUM},
2626
{c: "/v1/write/security", expect: Security},
2727
{c: "/v1/write/profiling", expect: Profiling},
28-
{c: "/v1/write/event", expect: KeyEvent},
28+
{c: "/v1/write/keyevent", expect: KeyEvent},
2929
{c: "/v1/write/tracing", expect: Tracing},
3030
{c: "/v1/write/dynamic_dw", expect: DynamicDWCategory},
3131
}
3232

3333
for _, tc := range cases {
3434
t.Run(tc.c, func(t *testing.T) {
35-
assert.Equal(t, tc.expect, CatURL(tc.c))
35+
assert.Equal(t, tc.expect.String(), CatURL(tc.c).String())
3636
})
3737
}
3838
}
@@ -76,7 +76,7 @@ func TestString(t *testing.T) {
7676
{c: "rum", expect: RUM},
7777
{c: "security", expect: Security},
7878
{c: "profiling", expect: Profiling},
79-
{c: "event", expect: KeyEvent},
79+
{c: "keyevent", expect: KeyEvent},
8080
{c: "tracing", expect: Tracing},
8181
{c: "dynamic_dw", expect: DynamicDWCategory},
8282
}

point/encode.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ import (
1313
"google.golang.org/protobuf/proto"
1414
)
1515

16+
type Encoding int
17+
18+
func EncodingStr(s string) Encoding {
19+
switch s {
20+
case "protobuf":
21+
return Protobuf
22+
case "lineproto", "lineprotocol":
23+
return LineProtocol
24+
default:
25+
return LineProtocol
26+
}
27+
}
28+
1629
// EncodeFn used to iterate on []*Point payload, if error returned, the iterate terminated.
1730
type EncodeFn func(batchSize int, payload []byte) error
1831

point/option.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ import (
1010
"time"
1111
)
1212

13-
type Encoding int
14-
15-
func EncodingStr(s string) Encoding {
16-
switch s {
17-
case "protobuf":
18-
return Protobuf
19-
case "lineproto", "lineprotocol":
20-
return LineProtocol
21-
default:
22-
return LineProtocol
23-
}
24-
}
25-
2613
const (
2714
LineProtocol Encoding = iota
2815
Protobuf
@@ -176,6 +163,7 @@ func WithRequiredKeys(keys ...*Key) Option {
176163
}
177164
}
178165

166+
// DefaultObjectOptions defined options on Object/CustomObject point.
179167
func DefaultObjectOptions() []Option {
180168
return []Option{
181169
WithDisabledKeys(disabledKeys[Object]...),
@@ -185,15 +173,16 @@ func DefaultObjectOptions() []Option {
185173
}
186174
}
187175

176+
// DefaultLoggingOptions defined options on Logging point.
188177
func DefaultLoggingOptions() []Option {
189-
return []Option{
178+
return append(CommonLoggingOptions(), []Option{
190179
WithDisabledKeys(disabledKeys[Logging]...),
191180
WithMaxFieldValLen(defaultMaxFieldValLen),
192-
WithDotInKey(false),
193181
WithRequiredKeys(requiredKeys[Logging]...),
194-
}
182+
}...)
195183
}
196184

185+
// DefaultMetricOptions defined options on Metric point.
197186
func DefaultMetricOptions() []Option {
198187
return []Option{
199188
WithStrField(false),
@@ -208,3 +197,10 @@ func DefaultMetricOptionsForInflux1X() []Option {
208197
WithU64Field(false),
209198
}
210199
}
200+
201+
// CommonLoggingOptions defined options on RUM/Tracing/Security/Event/Profile/Network point.
202+
func CommonLoggingOptions() []Option {
203+
return []Option{
204+
WithDotInKey(false),
205+
}
206+
}

0 commit comments

Comments
 (0)