reorganize pkg/util

This commit is contained in:
kongfei 2022-06-02 21:13:30 +08:00
parent 687c344c7b
commit 886b7a0cab
15 changed files with 9 additions and 60 deletions

View File

@ -9,8 +9,6 @@ import (
"expvar"
"sync"
"time"
"flashcat.cloud/categraf/pkg/util"
)
// SourceType used for log line parsing logic.
@ -47,7 +45,7 @@ type LogSource struct {
ParentSource *LogSource
// LatencyStats tracks internal stats on the time spent by messages from this source in a processing pipeline, i.e.
// the duration between when a message is decoded by the tailer/listener/decoder and when the message is handled by a sender
LatencyStats *util.StatsTracker
LatencyStats *StatsTracker
}
// NewLogSource creates a new log source.
@ -61,7 +59,7 @@ func NewLogSource(name string, config *LogsConfig) *LogSource {
Messages: NewMessages(),
BytesRead: expvar.Int{},
info: make(map[string]InfoProvider),
LatencyStats: util.NewStatsTracker(time.Hour*24, time.Hour),
LatencyStats: NewStatsTracker(time.Hour*24, time.Hour),
}
}

View File

@ -1,4 +1,4 @@
package util
package logs
import (
"sync"

View File

@ -14,8 +14,8 @@ import (
logsconfig "flashcat.cloud/categraf/config/logs"
"flashcat.cloud/categraf/logs/client"
"flashcat.cloud/categraf/pkg/util/backoff"
httputils "flashcat.cloud/categraf/pkg/util/http"
"flashcat.cloud/categraf/pkg/backoff"
httputils "flashcat.cloud/categraf/pkg/httpx"
)
// ContentType options,

View File

@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
//go:build systemd
// +build systemd
package journald
@ -13,7 +14,7 @@ import (
"strings"
"time"
"flashcat.cloud/categraf/pkg/util/cache"
"flashcat.cloud/categraf/pkg/cache"
)
const (

View File

@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package http
package httpx
import (
"log"

View File

@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package http
package httpx
import (
"crypto/tls"

View File

@ -1,50 +0,0 @@
package cache
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBasicCache(t *testing.T) {
m := map[string]interface{}{
"a": 1,
"b": "dos",
"c": struct{}{},
"d": []string{"42", "platypus"},
}
c := NewBasicCache()
for k, v := range m {
c.Add(k, v)
}
assert.Equal(t, len(m), c.Size())
for k, v := range m {
cached, found := c.Get(k)
assert.True(t, found)
assert.Equal(t, v, cached)
}
_, found := c.Get("notincache")
assert.False(t, found)
items := c.Items()
for k, v := range items {
assert.Equal(t, m[k], v)
}
wombat := "wombat"
initialTimestamp := c.GetModified()
c.modified = 0
c.Add("d", wombat)
cached, found := c.Get("d")
assert.True(t, found)
assert.Equal(t, cached, wombat)
assert.GreaterOrEqual(t, c.GetModified(), initialTimestamp)
for k := range m {
c.Remove(k)
}
assert.Equal(t, 0, c.Size())
}