Skip to content

Commit

Permalink
[refactor][metrics] Rename span storage metrics decorator package / f…
Browse files Browse the repository at this point in the history
…unctions (jaegertracing#6255)

## Which problem is this PR solving?
- Towards jaegertracing#6219

## Description of the changes
- This PR performs the following refactorings
  - Rename package `metrics` to `spanstoremetrics`
- Rename the constructor `NewReadMetricsDecorator` to
`NewReaderDecorator`
  - Rename `NewWriteMetrics` to `NewWriterDecorator`
- This PR will be followed up by a PR to add a metrics decorator for
`storage.Factory`

## How was this change tested?
- CI

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 authored Nov 26, 2024
1 parent ae0982e commit d6ca388
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
"github.com/jaegertracing/jaeger/storage/dependencystore"
metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

// all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store
Expand Down Expand Up @@ -224,7 +224,7 @@ func startQuery(
tm *tenancy.Manager,
telset telemetery.Setting,
) *queryApp.Server {
spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, telset.Metrics)
spanReader = spanstoremetrics.NewReaderDecorator(spanReader, telset.Metrics)
qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts)

server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/plugin/metrics/disabled"
"github.com/jaegertracing/jaeger/storage/metricsstore"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

var (
Expand Down Expand Up @@ -65,7 +65,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error {
return fmt.Errorf("cannot create span reader: %w", err)
}

spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, queryMetricsFactory)
spanReader = spanstoremetrics.NewReaderDecorator(spanReader, queryMetricsFactory)

depReader, err := f.CreateDependencyReader()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/jaegertracing/jaeger/plugin/storage"
"github.com/jaegertracing/jaeger/ports"
metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics"
spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

func main() {
Expand Down Expand Up @@ -91,7 +91,7 @@ func main() {
if err != nil {
logger.Fatal("Failed to create span reader", zap.Error(err))
}
spanReader = spanstoreMetrics.NewReadMetricsDecorator(spanReader, metricsFactory)
spanReader = spanstoremetrics.NewReaderDecorator(spanReader, metricsFactory)
dependencyReader, err := storageFactory.CreateDependencyReader()
if err != nil {
logger.Fatal("Failed to create dependency reader", zap.Error(err))
Expand Down
6 changes: 3 additions & 3 deletions pkg/cassandra/metrics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (

"github.com/jaegertracing/jaeger/pkg/cassandra"
"github.com/jaegertracing/jaeger/pkg/metrics"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

// Table is a collection of metrics about Cassandra write operations.
type Table struct {
storageMetrics.WriteMetrics
spanstoremetrics.WriteMetrics
}

// NewTable takes a metrics scope and creates a table metrics struct
func NewTable(factory metrics.Factory, tableName string) *Table {
t := storageMetrics.WriteMetrics{}
t := spanstoremetrics.WriteMetrics{}
metrics.Init(&t, factory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"table": tableName}}), nil)
return &Table{t}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/es"
eswrapper "github.com/jaegertracing/jaeger/pkg/es/wrapper"
"github.com/jaegertracing/jaeger/pkg/metrics"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

const (
Expand Down Expand Up @@ -217,7 +217,7 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
return nil, err
}

sm := storageMetrics.NewWriteMetrics(metricsFactory, "bulk_index")
sm := spanstoremetrics.NewWriterDecorator(metricsFactory, "bulk_index")
m := sync.Map{}

bulkProc, err := rawClient.BulkProcessor().
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
cfg "github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

const (
Expand All @@ -28,7 +28,7 @@ const (
)

type spanWriterMetrics struct {
indexCreate *storageMetrics.WriteMetrics
indexCreate *spanstoremetrics.WriteMetrics
}

type serviceWriter func(string, *dbmodel.Span)
Expand Down Expand Up @@ -72,7 +72,7 @@ func NewSpanWriter(p SpanWriterParams) *SpanWriter {
client: p.Client,
logger: p.Logger,
writerMetrics: spanWriterMetrics{
indexCreate: storageMetrics.NewWriteMetrics(p.MetricsFactory, "index_create"),
indexCreate: spanstoremetrics.NewWriterDecorator(p.MetricsFactory, "index_create"),
},
serviceWriter: serviceOperationStorage.Write,
spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package metrics_test
package spanstoremetrics_test

import (
"context"
Expand All @@ -14,15 +14,15 @@ import (
"github.com/jaegertracing/jaeger/internal/metricstest"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
"github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore/mocks"
"github.com/jaegertracing/jaeger/storage/spanstore/spanstoremetrics"
)

func TestSuccessfulUnderlyingCalls(t *testing.T) {
mf := metricstest.NewFactory(0)

mockReader := mocks.Reader{}
mrs := metrics.NewReadMetricsDecorator(&mockReader, mf)
mrs := spanstoremetrics.NewReaderDecorator(&mockReader, mf)
mockReader.On("GetServices", context.Background()).Return([]string{}, nil)
mrs.GetServices(context.Background())
operationQuery := spanstore.OperationQueryParameters{ServiceName: "something"}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestFailingUnderlyingCalls(t *testing.T) {
mf := metricstest.NewFactory(0)

mockReader := mocks.Reader{}
mrs := metrics.NewReadMetricsDecorator(&mockReader, mf)
mrs := spanstoremetrics.NewReaderDecorator(&mockReader, mf)
mockReader.On("GetServices", context.Background()).
Return(nil, errors.New("Failure"))
mrs.GetServices(context.Background())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package metrics
package spanstoremetrics

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package metrics
package spanstoremetrics

import (
"context"
Expand Down Expand Up @@ -42,8 +42,8 @@ func (q *queryMetrics) emit(err error, latency time.Duration, responses int) {
}
}

// NewReadMetricsDecorator returns a new ReadMetricsDecorator.
func NewReadMetricsDecorator(spanReader spanstore.Reader, metricsFactory metrics.Factory) *ReadMetricsDecorator {
// NewReaderDecorator returns a new ReadMetricsDecorator.
func NewReaderDecorator(spanReader spanstore.Reader, metricsFactory metrics.Factory) *ReadMetricsDecorator {
return &ReadMetricsDecorator{
spanReader: spanReader,
findTracesMetrics: buildQueryMetrics("find_traces", metricsFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package metrics
package spanstoremetrics

import (
"time"
Expand All @@ -19,8 +19,8 @@ type WriteMetrics struct {
LatencyErr metrics.Timer `metric:"latency-err"`
}

// NewWriteMetrics takes a metrics scope and creates a metrics struct
func NewWriteMetrics(factory metrics.Factory, tableName string) *WriteMetrics {
// NewWriterDecorator takes a metrics scope and creates a metrics struct
func NewWriterDecorator(factory metrics.Factory, tableName string) *WriteMetrics {
t := &WriteMetrics{}
metrics.Init(t, factory.Namespace(metrics.NSOptions{Name: tableName, Tags: nil}), nil)
return t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package metrics
package spanstoremetrics

import (
"errors"
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestTableEmit(t *testing.T) {
}
for _, tc := range testCases {
mf := metricstest.NewFactory(time.Second)
tm := NewWriteMetrics(mf, "a_table")
tm := NewWriterDecorator(mf, "a_table")
tm.Emit(tc.err, 50*time.Millisecond)
counts, gauges := mf.Snapshot()
assert.Equal(t, tc.counts, counts)
Expand Down

0 comments on commit d6ca388

Please sign in to comment.