Skip to content

Commit 3cb2382

Browse files
committed
Fix linter problems
1 parent 138f55c commit 3cb2382

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Diff for: clickhouse.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ var clickhouseMetrics = make(map[string]struct{})
2020
var clickhouseDb *sql.DB
2121
var clickhouseCtx = context.Background()
2222

23+
const clickhouseMetricType = "Nullable(Float32)"
24+
2325
func clickhouseCheckFieldName(name string) (result bool) {
2426
re := regexp.MustCompile(`^[^a-zA-Z0-9:\-_]+$`)
2527
result = re.MatchString(name)
2628
return !result
2729
}
2830

2931
func clickhouseAddMetric(fieldName, fieldType string) {
30-
if fieldType == "Nullable(Float32)" {
32+
if fieldType == clickhouseMetricType {
3133
clickhouseMetrics[fieldName] = struct{}{}
3234
clickhouseMetricCount = len(clickhouseMetrics)
3335
log.Info("Metric init ", fieldName)
@@ -125,6 +127,24 @@ func clickhouseWaitConnection() {
125127
}
126128
}
127129

130+
func clickhouseCreateMetric(name string) (ok bool) {
131+
if ok := clickhouseCheckFieldName(name); ok {
132+
_, err := clickhouseDb.Exec("ALTER TABLE `metrics` ADD COLUMN `$1` "+clickhouseMetricType, name)
133+
if err != nil {
134+
log.Errorf("Cant ADD COLUMN [%s] to database: %v", name, err)
135+
return false
136+
}
137+
138+
// TODO check error inside clickhouseAddMetric
139+
clickhouseAddMetric(name, clickhouseMetricType)
140+
} else {
141+
log.Warnf("Invalid COLUMN name [%s]", name)
142+
return false
143+
}
144+
145+
return true
146+
}
147+
128148
func clickhouseMetricInsert(timestamp int64, row map[string]float64) {
129149
clickhouseWaitConnection()
130150

@@ -137,18 +157,8 @@ func clickhouseMetricInsert(timestamp int64, row map[string]float64) {
137157
// check key name column exist in our ckickhouse DDL
138158
if _, ok := clickhouseMetrics[key]; !ok {
139159
// if not exist - create it by ALTER TABLE values ADD key float8
140-
if ok := clickhouseCheckFieldName(key); ok {
141-
_, err := clickhouseDb.Exec("ALTER TABLE `metrics` ADD COLUMN `$1` Nullable(Float32)", key)
142-
if err != nil {
143-
log.Errorf("Cant ADD COLUMN [%s] to database: %v", key, err)
144-
// TODO save request for feature send it to database (and return)
145-
continue
146-
}
147-
148-
// TODO check error inside clickhouseAddMetric
149-
clickhouseAddMetric(key, "Nullable(Float32)")
150-
} else {
151-
log.Warnf("Invalid COLUMN name [%s]", key)
160+
if ok := clickhouseCreateMetric(key); !ok {
161+
// TODO save request for feature send it to database (and return)
152162
continue
153163
}
154164
}

Diff for: esp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func espMessageHandler(topic string, payload []byte) {
133133
log.Debugf("Debug")
134134

135135
default:
136-
log.Warnf("Unknown topic Theme (%s) [%u] %s %s %s %u,"+
136+
log.Warnf("Unknown topic Theme (%s) [%d] %s %s %s,"+
137137
" we ignore it (but devs must fix this by adding esp handler for it)",
138138
espTheme, timestamp, espRoom, espTheme, payloadStr)
139139
}

0 commit comments

Comments
 (0)