Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix cache population when initializing metric batcher
Browse files Browse the repository at this point in the history
Series table name was not set correctly when initializing the metric batcher
creating issues when trying to query metrics. The issue would resolve itself
once the cache was dropped and recreated.
  • Loading branch information
antekresic authored and cevian committed Oct 12, 2021
1 parent c1dca01 commit f26bbfe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/pgmodel/ingestor/metric_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func initializeMetricBatcher(conn pgxconn.PgxConn, metricName string, completeMe
metricName,
model.MetricInfo{
TableSchema: schema.Data, TableName: tableName,
SeriesTable: "",
SeriesTable: tableName, // Series table name is always the same for raw metrics.
},
false,
)
Expand Down
30 changes: 30 additions & 0 deletions pkg/pgmodel/ingestor/metric_batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stretchr/testify/require"
"github.com/timescale/promscale/pkg/pgmodel/cache"
"github.com/timescale/promscale/pkg/pgmodel/common/schema"
"github.com/timescale/promscale/pkg/pgmodel/model"
pgmodel "github.com/timescale/promscale/pkg/pgmodel/model"
"github.com/timescale/promscale/pkg/prompb"
Expand Down Expand Up @@ -84,6 +85,35 @@ func TestMetricTableName(t *testing.T) {
}
}

func TestInitializeMetricBatcher(t *testing.T) {
metricName := "mock_metric"
metricTableName := "mock_metric_table_name"
sqlQueries := []model.SqlQuery{
{
Sql: "SELECT table_name, possibly_new FROM _prom_catalog.get_or_create_metric_table_name($1)",
Args: []interface{}{metricName},
Results: model.RowResults{{metricTableName, true}},
},
}
mock := model.NewSqlRecorder(sqlQueries, t)
mockMetrics := &model.MockMetricCache{
MetricCache: make(map[string]model.MetricInfo),
}
completeMetricCreation := make(chan struct{}, 1)

tableName, err := initializeMetricBatcher(mock, metricName, completeMetricCreation, mockMetrics)
require.Nil(t, err)
require.Equal(t, metricTableName, tableName)

// Double-check the cache was set properly.
mInfo, err := mockMetrics.Get(schema.Data, metricName, false)
require.Nil(t, err)
require.Equal(t, schema.Data, mInfo.TableSchema)
require.Equal(t, metricTableName, mInfo.TableName)
require.Equal(t, metricTableName, mInfo.SeriesTable)

}

type insertableVisitor []model.Insertable

func (insertables insertableVisitor) VisitExemplar(callBack func(s *pgmodel.PromExemplars) error) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pgmodel/model/sql_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (m *MockMetricCache) Get(schema, metric string, isExemplar bool) (MetricInf
}

func (m *MockMetricCache) Set(schema, metric string, mInfo MetricInfo, isExemplar bool) error {
m.MetricCache[schema+"*"+metric] = mInfo
m.MetricCache[fmt.Sprintf("%s_%s_%t", schema, metric, isExemplar)] = mInfo
return m.SetMetricErr
}

Expand Down

0 comments on commit f26bbfe

Please sign in to comment.