Skip to content
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

chore(tm2): OTEL / handle http metrics exporter #2402

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ require (
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
go.etcd.io/bbolt v1.3.9
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0
go.opentelemetry.io/otel/metric v1.25.0
go.opentelemetry.io/otel/sdk v1.25.0
go.opentelemetry.io/otel/sdk/metric v1.25.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
go.uber.org/zap/exp v0.2.0
golang.org/x/crypto v0.21.0
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/mod v0.16.0
golang.org/x/net v0.23.0
golang.org/x/sync v0.6.0
golang.org/x/term v0.18.0
golang.org/x/net v0.25.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.20.0
golang.org/x/tools v0.19.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -56,18 +57,18 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
)
71 changes: 36 additions & 35 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions tm2/pkg/telemetry/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import (
"context"
"fmt"
"net/url"

"github.com/gnolang/gno/tm2/pkg/telemetry/config"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
"go.opentelemetry.io/otel/metric"
sdkMetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -112,14 +114,35 @@
)

func Init(config config.Config) error {
// Use oltp metric exporter
exp, err := otlpmetricgrpc.New(
context.Background(),
otlpmetricgrpc.WithEndpoint(config.ExporterEndpoint),
otlpmetricgrpc.WithInsecure(),
var (
ctx = context.Background()
exp sdkMetric.Exporter

Check warning on line 119 in tm2/pkg/telemetry/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/telemetry/metrics/metrics.go#L117-L119

Added lines #L117 - L119 were not covered by tests
)

u, err := url.Parse(config.ExporterEndpoint)

Check warning on line 122 in tm2/pkg/telemetry/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/telemetry/metrics/metrics.go#L122

Added line #L122 was not covered by tests
if err != nil {
return fmt.Errorf("unable to create metrics exporter, %w", err)
return fmt.Errorf("error parsing exporter endpoint: %s, %w", config.ExporterEndpoint, err)

Check warning on line 124 in tm2/pkg/telemetry/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/telemetry/metrics/metrics.go#L124

Added line #L124 was not covered by tests
}

// Use oltp metric exporter with http/https or grpc
switch u.Scheme {
case "http", "https":
exp, err = otlpmetrichttp.New(
ctx,
otlpmetrichttp.WithEndpointURL(config.ExporterEndpoint),
albttx marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return fmt.Errorf("unable to create http metrics exporter, %w", err)

Check warning on line 135 in tm2/pkg/telemetry/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/telemetry/metrics/metrics.go#L128-L135

Added lines #L128 - L135 were not covered by tests
}
default:
exp, err = otlpmetricgrpc.New(
ctx,
otlpmetricgrpc.WithEndpoint(config.ExporterEndpoint),
otlpmetricgrpc.WithInsecure(),
)
if err != nil {
return fmt.Errorf("unable to create grpc metrics exporter, %w", err)

Check warning on line 144 in tm2/pkg/telemetry/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/telemetry/metrics/metrics.go#L137-L144

Added lines #L137 - L144 were not covered by tests
}
}

provider := sdkMetric.NewMeterProvider(
Expand Down
Loading