Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prometheus data writing fails when using ByConity database #8222

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
10 changes: 8 additions & 2 deletions server/ingester/prometheus/dbwriter/prometheus_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type PrometheusWriter struct {
appLabelColumnIncrement int
metricsWriterCache *ckwriter.CKWriter // the writer for prometheus.metrics table
flowTagWriter *flow_tag.FlowTagWriter
systemColumnsTableName string

counter *Counter
utils.Closable
Expand Down Expand Up @@ -270,7 +271,7 @@ func (w *PrometheusWriter) addAppLabelColumns(conn common.DBs, startIndex, endIn
}

func (w *PrometheusWriter) getCurrentAppLabelColumnCount(orgDatabase string) (int, error) {
sql := fmt.Sprintf("SELECT count(0) FROM system.columns where database='%s' and table='%s' and name like '%%app_label_value%%'", orgDatabase, PROMETHEUS_TABLE)
sql := fmt.Sprintf("SELECT count(0) FROM system.%s where database='%s' and table='%s' and name like '%%app_label_value%%'", w.systemColumnsTableName, orgDatabase, PROMETHEUS_TABLE)
log.Info(sql)
rows, err := w.ckdbConn.Query(sql)
if err != nil {
Expand All @@ -294,7 +295,7 @@ func (w *PrometheusWriter) getCurrentAppLabelColumnCount(orgDatabase string) (in

func (w *PrometheusWriter) getMaxAppLabelColumnIndex(orgDatabase string) (int, error) {
var name, maxName string
sql := fmt.Sprintf("WITH (SELECT max(length(name)) FROM system.columns where database='%s' and table='%s' and name like '%%app_label_value%%') as maxNameLength SELECT max(name) from system.columns where database='%s' and table='%s' and name like '%%app_label_value%%' and length(name)=maxNameLength", orgDatabase, PROMETHEUS_TABLE, orgDatabase, PROMETHEUS_TABLE)
sql := fmt.Sprintf("WITH (SELECT max(length(name)) FROM system.%s where database='%s' and table='%s' and name like '%%app_label_value%%') as maxNameLength SELECT max(name) from system.%s where database='%s' and table='%s' and name like '%%app_label_value%%' and length(name)=maxNameLength", w.systemColumnsTableName, orgDatabase, PROMETHEUS_TABLE, w.systemColumnsTableName, orgDatabase, PROMETHEUS_TABLE)
log.Info(sql)
rows, err := w.ckdbConn.Query(sql)
if err != nil {
Expand Down Expand Up @@ -373,6 +374,10 @@ func NewPrometheusWriter(
if err != nil {
return nil, err
}
systemColumnsTableName := "columns"
if config.Base.CKDB.Type == ckdb.CKDBTypeByconity {
systemColumnsTableName = "cnch_columns"
}

// PrometheusWriter
writer := &PrometheusWriter{
Expand All @@ -392,6 +397,7 @@ func NewPrometheusWriter(
writerConfig: ckWriterConfig,
flowTagWriter: flowTagWriter,
appLabelColumnIncrement: config.AppLabelColumnIncrement,
systemColumnsTableName: systemColumnsTableName,

counter: &Counter{},
}
Expand Down
Loading