-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add storage metrics to OTEL, metrics by span service name #2431
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,15 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"go.opencensus.io/stats" | ||
"go.opencensus.io/tag" | ||
"go.opentelemetry.io/collector/component/componenterror" | ||
"go.opentelemetry.io/collector/consumer/consumererror" | ||
"go.opentelemetry.io/collector/consumer/pdata" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/exporter/storagemetrics" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/esclient" | ||
"github.com/jaegertracing/jaeger/model" | ||
"github.com/jaegertracing/jaeger/pkg/cache" | ||
|
@@ -47,6 +50,7 @@ const ( | |
// esSpanWriter holds components required for ES span writer | ||
type esSpanWriter struct { | ||
logger *zap.Logger | ||
nameTag tag.Mutator | ||
client esclient.ElasticsearchClient | ||
serviceCache cache.Cache | ||
spanIndexName indexNameProvider | ||
|
@@ -56,7 +60,7 @@ type esSpanWriter struct { | |
} | ||
|
||
// newEsSpanWriter creates new instance of esSpanWriter | ||
func newEsSpanWriter(params config.Configuration, logger *zap.Logger, archive bool) (*esSpanWriter, error) { | ||
func newEsSpanWriter(params config.Configuration, logger *zap.Logger, archive bool, name string) (*esSpanWriter, error) { | ||
client, err := esclient.NewElasticsearchClient(params, logger) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -66,6 +70,8 @@ func newEsSpanWriter(params config.Configuration, logger *zap.Logger, archive bo | |
return nil, err | ||
} | ||
return &esSpanWriter{ | ||
logger: logger, | ||
nameTag: tag.Insert(storagemetrics.TagExporterName(), name), | ||
client: client, | ||
spanIndexName: newIndexNameProvider(spanIndexBaseName, params.IndexPrefix, params.UseReadWriteAliases, archive), | ||
serviceIndexName: newIndexNameProvider(serviceIndexBaseName, params.IndexPrefix, params.UseReadWriteAliases, archive), | ||
|
@@ -106,7 +112,7 @@ func (w *esSpanWriter) WriteTraces(ctx context.Context, traces pdata.Traces) (in | |
func (w *esSpanWriter) writeSpans(ctx context.Context, spans []*dbmodel.Span) (int, error) { | ||
buffer := &bytes.Buffer{} | ||
// mapping for bulk operation to span | ||
bulkOperations := make([]bulkItem, len(spans)) | ||
var bulkOperations []bulkItem | ||
var errs []error | ||
dropped := 0 | ||
for _, span := range spans { | ||
|
@@ -136,14 +142,17 @@ func (w *esSpanWriter) writeSpans(ctx context.Context, spans []*dbmodel.Span) (i | |
errs = append(errs, err) | ||
return len(spans), componenterror.CombineErrors(errs) | ||
} | ||
droppedFromResponse := w.handleResponse(res, bulkOperations) | ||
droppedFromResponse := w.handleResponse(ctx, res, bulkOperations) | ||
dropped += droppedFromResponse | ||
return dropped, componenterror.CombineErrors(errs) | ||
} | ||
|
||
func (w *esSpanWriter) handleResponse(blk *esclient.BulkResponse, operationToSpan []bulkItem) int { | ||
func (w *esSpanWriter) handleResponse(ctx context.Context, blk *esclient.BulkResponse, operationToSpan []bulkItem) int { | ||
numErrors := 0 | ||
storedSpans := map[string]int64{} | ||
notStoredSpans := map[string]int64{} | ||
for i, d := range blk.Items { | ||
bulkOp := operationToSpan[i] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how confident are we that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the lenght should match. The blk contains resposes for objects in operationToSpan. |
||
if d.Index.Status > 201 { | ||
numErrors++ | ||
w.logger.Error("Part of the bulk request failed", | ||
|
@@ -154,15 +163,29 @@ func (w *esSpanWriter) handleResponse(blk *esclient.BulkResponse, operationToSpa | |
zap.String("error.cause.reason", d.Index.Error.Cause.Reason)) | ||
// TODO return an error or a struct that indicates which spans should be retried | ||
// https://github.com/open-telemetry/opentelemetry-collector/issues/990 | ||
if !bulkOp.isService { | ||
notStoredSpans[bulkOp.span.Process.ServiceName] = notStoredSpans[bulkOp.span.Process.ServiceName] + 1 | ||
} | ||
} else { | ||
// passed | ||
bulkOp := operationToSpan[i] | ||
if bulkOp.isService { | ||
if !bulkOp.isService { | ||
storedSpans[bulkOp.span.Process.ServiceName] = storedSpans[bulkOp.span.Process.ServiceName] + 1 | ||
} else { | ||
cacheKey := hashCode(bulkOp.span.Process.ServiceName, bulkOp.span.OperationName) | ||
w.serviceCache.Put(cacheKey, cacheKey) | ||
} | ||
} | ||
} | ||
for k, v := range notStoredSpans { | ||
ctx, _ := tag.New(ctx, | ||
tag.Insert(storagemetrics.TagServiceName(), k), w.nameTag) | ||
stats.Record(ctx, storagemetrics.StatSpansNotStoredCount().M(v)) | ||
} | ||
for k, v := range storedSpans { | ||
ctx, _ := tag.New(ctx, | ||
tag.Insert(storagemetrics.TagServiceName(), k), w.nameTag) | ||
stats.Record(ctx, storagemetrics.StatSpansStoredCount().M(v)) | ||
} | ||
return numErrors | ||
} | ||
|
||
|
67 changes: 67 additions & 0 deletions
67
cmd/opentelemetry/app/exporter/elasticsearchexporter/spanstore_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package elasticsearchexporter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opencensus.io/stats/view" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/exporter/storagemetrics" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/esclient" | ||
"github.com/jaegertracing/jaeger/pkg/es/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
w, err := newEsSpanWriter(config.Configuration{Servers: []string{"localhost:9200"}, Version: 6}, zap.NewNop(), false, "elasticsearch") | ||
require.NoError(t, err) | ||
response := &esclient.BulkResponse{} | ||
response.Items = []esclient.BulkResponseItem{ | ||
{Index: esclient.BulkIndexResponse{Status: 200}}, | ||
{Index: esclient.BulkIndexResponse{Status: 500}}, | ||
{Index: esclient.BulkIndexResponse{Status: 200}}, | ||
{Index: esclient.BulkIndexResponse{Status: 500}}, | ||
} | ||
blkItms := []bulkItem{ | ||
{isService: true, span: &dbmodel.Span{}}, | ||
{isService: true, span: &dbmodel.Span{}}, | ||
{span: &dbmodel.Span{Process: dbmodel.Process{ServiceName: "foo"}}}, | ||
{span: &dbmodel.Span{Process: dbmodel.Process{ServiceName: "foo"}}}, | ||
} | ||
|
||
views := storagemetrics.MetricViews() | ||
require.NoError(t, view.Register(views...)) | ||
defer view.Unregister(views...) | ||
|
||
errs := w.handleResponse(context.Background(), response, blkItms) | ||
assert.Equal(t, 2, errs) | ||
|
||
viewData, err := view.RetrieveData(storagemetrics.StatSpansStoredCount().Name()) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(viewData)) | ||
distData := viewData[0].Data.(*view.SumData) | ||
assert.Equal(t, float64(1), distData.Value) | ||
|
||
viewData, err = view.RetrieveData(storagemetrics.StatSpansNotStoredCount().Name()) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(viewData)) | ||
distData = viewData[0].Data.(*view.SumData) | ||
assert.Equal(t, float64(1), distData.Value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the storage factory has a similar impl I have used that instead.