fix(clickhouse): resolve lint issues from optimization stack

This commit is contained in:
ryan
2026-07-02 15:28:49 +08:00
parent caf2ffcff4
commit 38946d1af5
6 changed files with 27 additions and 26 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# ClickHouse CPU 性能优化计划
> PLAN_ID: `63ba981b`
> 状态: 执行中
> 状态: 已完成
> 目标: 完成 P0–P2 优化,降低 ClickHouse CPU 占用
## 背景
@@ -235,7 +235,7 @@ func buildNodeAccessLogRecords(nodeID string, direct []NodeAccessLog, buffered [
return records, nil
}
func persistNodeAccessLogs(ctx context.Context, nodeID string, records []*model.OpenFlareAccessLog, reportedAt time.Time) error {
func persistNodeAccessLogs(ctx context.Context, _ string, records []*model.OpenFlareAccessLog, _ time.Time) error {
if len(records) == 0 {
return nil
}
@@ -26,10 +26,7 @@ const (
accessLogFieldRequestCount = "request_count"
)
var (
nodeAccessLogRetentionWindow = nodeAccessLogRetentionDays * 24 * time.Hour
defaultAccessLogQueryWindow = defaultAccessLogQueryDays * 24 * time.Hour
)
var defaultAccessLogQueryWindow = defaultAccessLogQueryDays * 24 * time.Hour
// AccessLogQuery filters access log list queries.
type AccessLogQuery struct {
@@ -329,11 +329,6 @@ func normalizeIPLiteral(value string) (string, bool) {
return addr.String(), true
}
func hostIsIPLiteral(value string) bool {
_, ok := normalizeIPLiteral(value)
return ok
}
func downloadIPGroupSubscription(ctx context.Context, rawURL string) ([]byte, error) {
if err := validateSubscriptionURL(rawURL); err != nil {
return nil, err
@@ -6,6 +6,7 @@ package model
import (
"context"
"net"
"net/http"
"net/netip"
"sort"
"strings"
@@ -343,13 +344,13 @@ func (s *memoryAccessLogStore) WAFIPAggregates(_ context.Context, filter OpenFla
}
item.RequestCount++
item.StatusCounts[row.StatusCode]++
if row.StatusCode == 404 {
if row.StatusCode == http.StatusNotFound {
item.Status404Count++
}
if row.StatusCode >= 400 && row.StatusCode < 500 {
item.ClientErrorCount++
}
if row.StatusCode >= 500 {
if row.StatusCode >= http.StatusInternalServerError {
item.ServerErrorCount++
}
if memoryAccessLogHostIsIPLiteral(row.Host) {
@@ -9,7 +9,15 @@ import (
"time"
)
const nodeAccessLogFilterClauseCapacity = 6
const (
nodeAccessLogFilterClauseCapacity = 6
nodeAccessLogSortDesc = "DESC"
nodeAccessLogSortAsc = "ASC"
nodeAccessLogSortAscInput = "asc"
nodeAccessLogColumnRemoteAddr = "remote_addr"
)
// NodeAccessLogFilter scopes ClickHouse node access log queries.
type NodeAccessLogFilter struct {
@@ -66,16 +74,16 @@ func combineNodeAccessLogSQLClauses(left string, right string) string {
}
func nodeAccessLogOrderClause(sortBy string, sortOrder string) string {
direction := "DESC"
if normalizeNodeAccessLogSortOrder(sortOrder) == "asc" {
direction = "ASC"
direction := nodeAccessLogSortDesc
if normalizeNodeAccessLogSortOrder(sortOrder) == nodeAccessLogSortAscInput {
direction = nodeAccessLogSortAsc
}
column := "logged_at"
switch strings.TrimSpace(sortBy) {
case "status_code":
column = "status_code"
case "remote_addr":
column = "remote_addr"
case nodeAccessLogColumnRemoteAddr:
column = nodeAccessLogColumnRemoteAddr
case "host":
column = "host"
case "path":
@@ -110,9 +118,9 @@ func nodeAccessLogHostIsIPLiteralExpr() string {
}
func nodeAccessLogBucketOrderClause(sortBy string, sortOrder string) string {
direction := "DESC"
if normalizeNodeAccessLogSortOrder(sortOrder) == "asc" {
direction = "ASC"
direction := nodeAccessLogSortDesc
if normalizeNodeAccessLogSortOrder(sortOrder) == nodeAccessLogSortAscInput {
direction = nodeAccessLogSortAsc
}
switch strings.TrimSpace(sortBy) {
case "request_count":
@@ -123,9 +131,9 @@ func nodeAccessLogBucketOrderClause(sortBy string, sortOrder string) string {
}
func nodeAccessLogIPSummaryOrderClause(sortBy string, sortOrder string) string {
direction := "DESC"
if normalizeNodeAccessLogSortOrder(sortOrder) == "asc" {
direction = "ASC"
direction := nodeAccessLogSortDesc
if normalizeNodeAccessLogSortOrder(sortOrder) == nodeAccessLogSortAscInput {
direction = nodeAccessLogSortAsc
}
column := "total_requests"
switch strings.TrimSpace(sortBy) {
@@ -133,7 +141,7 @@ func nodeAccessLogIPSummaryOrderClause(sortBy string, sortOrder string) string {
column = "recent_requests"
case "last_seen_at":
column = "last_seen_epoch"
case "remote_addr":
case nodeAccessLogColumnRemoteAddr:
column = "trimmed_remote_addr"
}
return column + " " + direction + ", last_seen_epoch DESC, trimmed_remote_addr ASC"