Skip to content

Commit

Permalink
fix the ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
masonmei committed Jul 27, 2023
1 parent 93f9459 commit 11d5576
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: clickhouseexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change writing of metrics data to batch

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24403]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
98 changes: 30 additions & 68 deletions exporter/clickhouseexporter/exporter_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,93 +46,55 @@ func TestExporter_pushMetricsData(t *testing.T) {
})
t.Run("check Resource metadata and scope metadata", func(t *testing.T) {
items := &atomic.Int32{}
resourceSchemaIdx := []int{1, 2, 2}

itemIdxs := map[string]*atomic.Uint32{
"otel_metrics_exponential_histogram": {},
"otel_metrics_gauge": {},
"otel_metrics_histogram": {},
"otel_metrics_sum": {},
"otel_metrics_summary": {},
}
initClickhouseTestServer(t, func(query string, values []driver.Value) error {
if strings.HasPrefix(query, "INSERT") {
items.Add(1)
if strings.HasPrefix(query, "INSERT INTO otel_metrics_exponential_histogram") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])

require.Equal(t, "Resource SchemaUrl 2", values[30])
require.Equal(t, "Scope name 2", values[31])
idx := itemIdxs["otel_metrics_exponential_histogram"]
require.Equal(t, fmt.Sprintf("Resource SchemaUrl %d", resourceSchemaIdx[idx.Load()]), values[1])
idx.Add(1)
require.Equal(t, fmt.Sprintf("Scope name %d", idx.Load()), values[2])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_gauge") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])

require.Equal(t, "Resource SchemaUrl 2", values[21])
require.Equal(t, "Scope name 2", values[22])
idx := itemIdxs["otel_metrics_gauge"]
require.Equal(t, fmt.Sprintf("Resource SchemaUrl %d", resourceSchemaIdx[idx.Load()]), values[1])
idx.Add(1)
require.Equal(t, fmt.Sprintf("Scope name %d", idx.Load()), values[2])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_histogram") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])

require.Equal(t, "Resource SchemaUrl 2", values[26])
require.Equal(t, "Scope name 2", values[27])
idx := itemIdxs["otel_metrics_histogram"]
require.Equal(t, fmt.Sprintf("Resource SchemaUrl %d", resourceSchemaIdx[idx.Load()]), values[1])
idx.Add(1)
require.Equal(t, fmt.Sprintf("Scope name %d", idx.Load()), values[2])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_sum (") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])

require.Equal(t, "Resource SchemaUrl 2", values[23])
require.Equal(t, "Scope name 2", values[24])
idx := itemIdxs["otel_metrics_sum"]
require.Equal(t, fmt.Sprintf("Resource SchemaUrl %d", resourceSchemaIdx[idx.Load()]), values[1])
idx.Add(1)
require.Equal(t, fmt.Sprintf("Scope name %d", idx.Load()), values[2])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_summary") {
require.Equal(t, "Resource SchemaUrl 1", values[1])
require.Equal(t, "Scope name 1", values[2])

require.Equal(t, "Resource SchemaUrl 2", values[19])
require.Equal(t, "Scope name 2", values[20])
idx := itemIdxs["otel_metrics_summary"]
require.Equal(t, fmt.Sprintf("Resource SchemaUrl %d", resourceSchemaIdx[idx.Load()]), values[1])
idx.Add(1)
require.Equal(t, fmt.Sprintf("Scope name %d", idx.Load()), values[2])
}
}
return nil
})
exporter := newTestMetricsExporter(t)
mustPushMetricsData(t, exporter, simpleMetrics(1))

require.Equal(t, int32(5), items.Load())
})
t.Run("check one resource metrics contain different scope metrics", func(t *testing.T) {
initClickhouseTestServer(t, func(query string, values []driver.Value) error {
if strings.HasPrefix(query, "INSERT INTO otel_metrics_exponential_histogram") {
require.Equal(t, "Resource SchemaUrl 2", values[30])
require.Equal(t, "Scope name 2", values[31])

require.Equal(t, "Resource SchemaUrl 2", values[59])
require.Equal(t, "Scope name 3", values[60])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_gauge") {
require.Equal(t, "Resource SchemaUrl 2", values[21])
require.Equal(t, "Scope name 2", values[22])

require.Equal(t, "Resource SchemaUrl 2", values[41])
require.Equal(t, "Scope name 3", values[42])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_histogram") {
require.Equal(t, "Resource SchemaUrl 2", values[26])
require.Equal(t, "Scope name 2", values[27])

require.Equal(t, "Resource SchemaUrl 2", values[51])
require.Equal(t, "Scope name 3", values[52])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_sum (") {
require.Equal(t, "Resource SchemaUrl 2", values[23])
require.Equal(t, "Scope name 2", values[24])

require.Equal(t, "Resource SchemaUrl 2", values[45])
require.Equal(t, "Scope name 3", values[46])
}
if strings.HasPrefix(query, "INSERT INTO otel_metrics_summary") {
require.Equal(t, "Resource SchemaUrl 2", values[19])
require.Equal(t, "Scope name 2", values[20])

require.Equal(t, "Resource SchemaUrl 2", values[37])
require.Equal(t, "Scope name 3", values[38])
}
return nil
})
exporter := newTestMetricsExporter(t)
mustPushMetricsData(t, exporter, simpleMetrics(1))
require.Equal(t, int32(15), items.Load())
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (e *expHistogramMetrics) insert(ctx context.Context, db *sql.DB) error {
defer func() {
_ = statement.Close()
}()

for _, model := range e.expHistogramModels {
for i := 0; i < model.expHistogram.DataPoints().Len(); i++ {
dp := model.expHistogram.DataPoints().At(i)
Expand Down
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/internal/gauge_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (g *gaugeMetrics) insert(ctx context.Context, db *sql.DB) error {
if err != nil {
return err
}

defer func() {
_ = statement.Close()
}()
Expand Down
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/internal/histogram_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (h *histogramMetrics) insert(ctx context.Context, db *sql.DB) error {
if err != nil {
return err
}

defer func() {
_ = statement.Close()
}()
Expand Down
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/internal/sum_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *sumMetrics) insert(ctx context.Context, db *sql.DB) error {
if err != nil {
return err
}

defer func() {
_ = statement.Close()
}()
Expand Down

0 comments on commit 11d5576

Please sign in to comment.