Skip to content

Commit

Permalink
Configure OTEL Collector to observe Internal Telemetry (#5752)
Browse files Browse the repository at this point in the history
**Which problem is this PR solving?**

This PR addresses a part of the issue [#5633
](#5633)

**Description of the changes**
This is a Draft PR to achieve Observability Parity between V1 and V2
components by configuring OTEL Collector config files to initialise
internal tracer and metrics
**How was this change tested?**

The changes were tested by running the following command:

```bash
make test
```
```bash
CI actions
```
**Checklist**

- [x] I have read
[CONTRIBUTING_GUIDELINES.md](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: Wise-Wizard <[email protected]>
Signed-off-by: Yuri Shkuro <[email protected]>
Signed-off-by: Saransh Shankar <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent e437971 commit 0f687f4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/all-in-one/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func healthCheck(t *testing.T) {
}

func httpGet(t *testing.T, url string) (*http.Response, []byte) {
t.Logf("Executing HTTP GET %s", url)
req, err := http.NewRequest(http.MethodGet, url, nil)
require.NoError(t, err)
req.Close = true // avoid persistent connections which leak goroutines
Expand Down
7 changes: 7 additions & 0 deletions cmd/jaeger/internal/all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ service:
receivers: [otlp, jaeger, zipkin]
processors: [batch]
exporters: [jaeger_storage_exporter]
telemetry:
resource:
service.name: jaeger
metrics:
level: detailed
# TODO Initialize telemetery tracer once OTEL released new feature.
# https://github.com/open-telemetry/opentelemetry-collector/issues/10663

extensions:
jaeger_query:
Expand Down
10 changes: 8 additions & 2 deletions cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import (
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
queryApp "github.com/jaegertracing/jaeger/cmd/query/app"
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
"github.com/jaegertracing/jaeger/internal/metrics/otelmetrics"
"github.com/jaegertracing/jaeger/pkg/jtracer"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/telemetery"
"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"
)

var (
Expand Down Expand Up @@ -46,6 +49,8 @@ func (*server) Dependencies() []component.ID {
}

func (s *server) Start(_ context.Context, host component.Host) error {
mf := otelmetrics.NewFactory(s.telset.MeterProvider)
queryMetricsFactory := mf.Namespace(metrics.NSOptions{Name: "query"})
f, err := jaegerstorage.GetStorageFactory(s.config.TraceStoragePrimary, host)
if err != nil {
return fmt.Errorf("cannot find primary storage %s: %w", s.config.TraceStoragePrimary, err)
Expand All @@ -55,8 +60,8 @@ func (s *server) Start(_ context.Context, host component.Host) error {
if err != nil {
return fmt.Errorf("cannot create span reader: %w", err)
}
// TODO
// spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, baseFactory.Namespace(metrics.NSOptions{Name: "query"}))

spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, queryMetricsFactory)

depReader, err := f.CreateDependencyReader()
if err != nil {
Expand Down Expand Up @@ -87,6 +92,7 @@ func (s *server) Start(_ context.Context, host component.Host) error {
telset := telemetery.Setting{
Logger: s.telset.Logger,
TracerProvider: tracerProvider.OTEL,
Metrics: queryMetricsFactory,
ReportStatus: s.telset.ReportStatus,
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
noopMeter "go.opentelemetry.io/otel/metric/noop"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

Expand Down Expand Up @@ -186,8 +187,9 @@ func TestServerStart(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
telemetrySettings := component.TelemetrySettings{
Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())),
ReportStatus: func(*component.StatusEvent) {},
Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())),
MeterProvider: noopMeter.NewMeterProvider(),
ReportStatus: func(*component.StatusEvent) {},
}
tt.config.HTTP.Endpoint = ":0"
tt.config.GRPC.NetAddr.Endpoint = ":0"
Expand Down
62 changes: 62 additions & 0 deletions scripts/compare_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Run the following commands first to create the JSON files:
# Run V1 Binary
# prom2json http://localhost:14269/metrics > V1_Metrics.json
# Run V2 Binary
# prom2json http://localhost:8888/metrics > V2_Metrics.json

import json

# Load the JSON files
v1_metrics_path = "./V1_Metrics.json"
v2_metrics_path = "./V2_Metrics.json"

with open(v1_metrics_path, 'r') as file:
v1_metrics = json.load(file)

with open(v2_metrics_path, 'r') as file:
v2_metrics = json.load(file)

# Extract names and labels of the metrics
def extract_metrics_with_labels(metrics):
result = {}
for metric in metrics:
name = metric['name']
labels = {}
if 'metrics' in metric and 'labels' in metric['metrics'][0]:
labels = metric['metrics'][0]['labels']
result[name] = labels
return result

v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics)
v2_metrics_with_labels = extract_metrics_with_labels(v2_metrics)

# Compare the metrics names and labels
common_metrics = {}
v1_only_metrics = {}
v2_only_metrics = {}

for name, labels in v1_metrics_with_labels.items():
if name in v2_metrics_with_labels:
if labels == v2_metrics_with_labels[name]:
common_metrics[name] = labels
else:
v1_only_metrics[name] = labels
else:
v1_only_metrics[name] = labels

for name, labels in v2_metrics_with_labels.items():
if name not in v1_metrics_with_labels:
v2_only_metrics[name] = labels

differences = {
"common_metrics": common_metrics,
"v1_only_metrics": v1_only_metrics,
"v2_only_metrics": v2_only_metrics
}

# Write the differences to a new JSON file
differences_path = "./differences.json"
with open(differences_path, 'w') as file:
json.dump(differences, file, indent=4)

print(f"Differences written to {differences_path}")

0 comments on commit 0f687f4

Please sign in to comment.