Skip to content

Commit

Permalink
feat: add signoz_error_index_v2 (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
makeavish committed Jul 13, 2022
1 parent 47e24e2 commit f8435c3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/signoz-otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ exporters:
resource_to_telemetry_conversion:
enabled: true
clickhousetraces:
datasource: http://stagingapp.signoz.io:9000/?database=signoz_traces
datasource: http://localhost:9000/?database=signoz_traces
migrations: ../../exporter/clickhousetracesexporter/migrations
clickhousemetricswrite:
endpoint: http://stagingapp.signoz.io:9000/?database=signoz_metrics
endpoint: http://localhost:9000/?database=signoz_metrics
resource_to_telemetry_conversion:
enabled: true

Expand Down
4 changes: 4 additions & 0 deletions exporter/clickhousetracesexporter/clickhouse_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package clickhousetracesexporter

import (
"context"
"crypto/md5"
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -195,6 +197,8 @@ func populateEvents(events pdata.SpanEventSlice, span *Span) {
uuidWithHyphen := uuid.New()
uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
span.ErrorID = uuid
hmd5 := md5.Sum([]byte(span.ServiceName + span.ErrorEvent.AttributeMap["exception.type"] + span.ErrorEvent.AttributeMap["exception.message"]))
span.ErrorGroupID = fmt.Sprintf("%x", hmd5)
}
stringEvent, _ := json.Marshal(event)
span.Events = append(span.Events, string(stringEvent))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS signoz_traces.signoz_error_index_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE IF NOT EXISTS signoz_traces.signoz_error_index_v2 (
timestamp DateTime64(9) CODEC(DoubleDelta, LZ4),
errorID FixedString(32) CODEC(ZSTD(1)),
groupID FixedString(32) CODEC(ZSTD(1)),
traceID FixedString(32) CODEC(ZSTD(1)),
spanID String CODEC(ZSTD(1)),
serviceName LowCardinality(String) CODEC(ZSTD(1)),
exceptionType LowCardinality(String) CODEC(ZSTD(1)),
exceptionMessage String CODEC(ZSTD(1)),
exceptionStacktrace String CODEC(ZSTD(1)),
exceptionEscaped bool CODEC(T64, ZSTD(1)),
INDEX idx_error_id errorID TYPE bloom_filter GRANULARITY 4
) ENGINE MergeTree()
PARTITION BY toDate(timestamp)
ORDER BY (timestamp, groupID)
2 changes: 1 addition & 1 deletion exporter/clickhousetracesexporter/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
defaultMigrations string = "/migrations"
defaultOperationsTable string = "signoz_operations"
defaultIndexTable string = "signoz_index_v2"
defaultErrorTable string = "signoz_error_index"
defaultErrorTable string = "signoz_error_index_v2"
defaultSpansTable string = "signoz_spans"
defaultArchiveSpansTable string = "signoz_archive_spans"
defaultWriteBatchDelay time.Duration = 5 * time.Second
Expand Down
1 change: 1 addition & 0 deletions exporter/clickhousetracesexporter/schema-signoz.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Span struct {
Events []string `json:"event,omitempty"`
ErrorEvent Event `json:"errorEvent,omitempty"`
ErrorID string `json:"errorID,omitempty"`
ErrorGroupID string `json:"errorGroupID,omitempty"`
TagMap map[string]string `json:"tagMap,omitempty"`
HasError bool `json:"hasError,omitempty"`
TraceModel TraceModel `json:"traceModel,omitempty"`
Expand Down
12 changes: 10 additions & 2 deletions exporter/clickhousetracesexporter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -195,14 +196,14 @@ func (w *SpanWriter) writeErrorBatch(batchSpans []*Span) error {
err = statement.Append(
time.Unix(0, int64(span.ErrorEvent.TimeUnixNano)),
span.ErrorID,
span.ErrorGroupID,
span.TraceId,
span.SpanId,
span.ParentSpanId,
span.ServiceName,
span.ErrorEvent.AttributeMap["exception.type"],
span.ErrorEvent.AttributeMap["exception.message"],
span.ErrorEvent.AttributeMap["exception.stacktrace"],
span.ErrorEvent.AttributeMap["exception.escaped"],
stringToBool(span.ErrorEvent.AttributeMap["exception.escaped"]),
)
if err != nil {
return err
Expand All @@ -212,6 +213,13 @@ func (w *SpanWriter) writeErrorBatch(batchSpans []*Span) error {
return statement.Send()
}

func stringToBool(s string) bool {
if strings.ToLower(s) == "true" {
return true
}
return false
}

func (w *SpanWriter) writeModelBatch(batchSpans []*Span) error {
ctx := context.Background()
statement, err := w.db.PrepareBatch(ctx, fmt.Sprintf("INSERT INTO %s.%s", w.traceDatabase, w.spansTable))
Expand Down

0 comments on commit f8435c3

Please sign in to comment.