Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/inserter/inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func NewInserter(clickhouseOptions ClickHouseOptions, runtimeInfo RuntimeInfo, n
w := worker{
waitAsyncInsert: clickhouseOptions.WaitForAsyncInsert,
conn: conn,
database: clickhouseOptions.Database,
batch: make([]string, 0, clickhouseOptions.BatchSize),
batchExpirationTimer: time.NewTimer(clickhouseOptions.BatchSendTimeout),
batchSendTimeout: clickhouseOptions.BatchSendTimeout,
Expand Down
73 changes: 37 additions & 36 deletions pkg/inserter/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type worker struct {

waitAsyncInsert bool
conn driver.Conn
database string
batch []string
batchCreationTimestamp time.Time
batchExpirationTimer *time.Timer
Expand Down Expand Up @@ -246,44 +247,44 @@ func (w *worker) flush() error {
}()

ctx := clickhouse.Context(context.Background(), clickhouse.WithSettings(clickhouse.Settings{"insert_deduplication_token": uuid.New().String()}))
q := `
INSERT INTO default.network_flows_0
q := fmt.Sprintf(`
INSERT INTO %s.network_flows_0
(
date,
intervalStartTime,
intervalSeconds,
environment,
proto,
connectionClass,
connectionFlags,
direction,
localCloud,
localRegion,
localCluster,
localAvailabilityZone,
localNode,
localInstanceID,
localNamespace,
localPod,
localIPv4,
localPort,
localApp,
remoteCloud,
remoteRegion,
remoteCluster,
remoteAvailabilityZone,
remoteNode,
remoteInstanceID,
remoteNamespace,
remotePod,
remoteIPv4,
remotePort,
remoteApp,
remoteCloudService,
bytes,
packets
date,
intervalStartTime,
intervalSeconds,
environment,
proto,
connectionClass,
connectionFlags,
direction,
localCloud,
localRegion,
localCluster,
localAvailabilityZone,
localNode,
localInstanceID,
localNamespace,
localPod,
localIPv4,
localPort,
localApp,
remoteCloud,
remoteRegion,
remoteCluster,
remoteAvailabilityZone,
remoteNode,
remoteInstanceID,
remoteNamespace,
remotePod,
remoteIPv4,
remotePort,
remoteApp,
remoteCloudService,
bytes,
packets
)
VALUES ` + strings.Join(w.batch, ", ")
VALUES %s`, w.database, strings.Join(w.batch, ", "))
if err1 := w.conn.AsyncInsert(ctx, q, w.waitAsyncInsert); err1 != nil {
insertRetryCounter.Inc()
log.Err(err1).Msg("failed to insert, going to retry")
Expand Down