Skip to content

Commit 44ffbdf

Browse files
committed
Calculate sha256 checksum for document _id for Elasticsearch.
Instead of using arbitrary string (which length can be quite big) as document _id we compute sha256 from it instead. Signed-off-by: Łukasz Harasimowicz <dev@harnash.eu>
1 parent 6f43001 commit 44ffbdf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

plugin/storage/es/spanstore/service_operation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package spanstore
1616

1717
import (
1818
"context"
19+
"crypto/sha256"
1920
"fmt"
2021
"time"
2122

@@ -75,9 +76,10 @@ func (s *ServiceOperationStorage) Write(indexName string, jsonSpan *jModel.Span)
7576
OperationName: jsonSpan.OperationName,
7677
}
7778
serviceID := fmt.Sprintf("%s|%s", service.ServiceName, service.OperationName)
79+
hashedID := fmt.Sprintf("%x", sha256.Sum256([]byte(serviceID)))
7880
cacheKey := fmt.Sprintf("%s:%s", indexName, serviceID)
7981
if !keyInCache(cacheKey, s.serviceCache) {
80-
s.client.Index().Index(indexName).Type(serviceType).BodyJson(service).Add()
82+
s.client.Index().Index(indexName).Type(serviceType).Id(hashedID).BodyJson(service).Add()
8183
writeCache(cacheKey, s.serviceCache)
8284
}
8385
}

0 commit comments

Comments
 (0)