Skip to content

Commit

Permalink
Remove metrics counters
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodm committed Nov 29, 2024
1 parent 1eb21b7 commit 0c1fb9d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
8 changes: 0 additions & 8 deletions cmd/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ User profiles can be configured with a "config.yml" file in the profile director

loc, err := locations.NewLocationManager()
if err != nil {
// telemetry.ProfilesListFailureCnt.Add(globalCtx, 1)
span.SetStatus(codes.Error, "error fetching profile")
return fmt.Errorf("error fetching profile: %w", err)
}
Expand All @@ -132,20 +131,17 @@ User profiles can be configured with a "config.yml" file in the profile director
_, fetchSpan := telemetry.CmdTracer.Start(globalCtx, "Fetch all profiles")
profileList, err := profile.FetchAllProfiles(loc.ProfileDir())
if err != nil {
// telemetry.ProfilesListFailureCnt.Add(globalCtx, 1)
fetchSpan.SetStatus(codes.Error, "error listing all profiles")
return fmt.Errorf("error listing all profiles: %w", err)
}
if len(profileList) == 0 {
fmt.Println("There are no profiles yet.")
// telemetry.ProfilesListSuccessCnt.Add(globalCtx, 1)
return nil
}
fetchSpan.End()

format, err := cmd.Flags().GetString(cobraext.ProfileFormatFlagName)
if err != nil {
// telemetry.ProfilesListFailureCnt.Add(globalCtx, 1)
span.SetStatus(codes.Error, "flag error")
return cobraext.FlagParsingError(err, cobraext.ProfileFormatFlagName)
}
Expand All @@ -162,7 +158,6 @@ User profiles can be configured with a "config.yml" file in the profile director
var config *install.ApplicationConfiguration
config, err = install.Configuration()
if err != nil {
telemetry.ProfilesListFailureCnt.Add(globalCtx, 1)
formatSpan.SetStatus(codes.Error, "failed to retrieve elastic-package configuration")
return fmt.Errorf("failed to load current configuration: %w", err)
}
Expand All @@ -175,9 +170,6 @@ User profiles can be configured with a "config.yml" file in the profile director
if err != nil {
formatSpan.RecordError(err)
formatSpan.SetStatus(codes.Error, "error formatting profiles")
// telemetry.ProfilesListFailureCnt.Add(globalCtx, 1)
} else {
// telemetry.ProfilesListSuccessCnt.Add(globalCtx, 1)
}
formatSpan.End()
return err
Expand Down
45 changes: 2 additions & 43 deletions internal/telemetry/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
Expand All @@ -26,8 +25,7 @@ var (
CmdTracer trace.Tracer
CmdMeter metric.Meter

ProfilesListSuccessCnt metric.Int64Counter
ProfilesListFailureCnt metric.Int64Counter
enabledTelemetry bool
)

func defaultResources(version string) (*resource.Resource, error) {
Expand Down Expand Up @@ -75,15 +73,7 @@ func SetupOTelSDK(ctx context.Context, version string) (shutdown func(context.Co
return nil, fmt.Errorf("failed to set up default Resource configuration: %w", err)
}

meterProvider, err := newMeterProvider(ctx, res)
if err != nil {
handleErr(err)
return
}

shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown)
otel.SetMeterProvider(meterProvider)

// TODO: Check if this is actually needed
prop := newPropagator()
otel.SetTextMapPropagator(prop)

Expand All @@ -98,21 +88,6 @@ func SetupOTelSDK(ctx context.Context, version string) (shutdown func(context.Co
return
}

func newMeterProvider(ctx context.Context, res *resource.Resource) (*sdkmetric.MeterProvider, error) {
metricReader, err := autoexport.NewMetricReader(ctx)
if err != nil {
return nil, err
}

meterProvider := sdkmetric.NewMeterProvider(
sdkmetric.WithResource(res),
sdkmetric.WithReader(
metricReader,
),
)
return meterProvider, nil
}

func newPropagator() propagation.TextMapPropagator {
return propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
Expand All @@ -135,19 +110,3 @@ func newTraceProvider(ctx context.Context, res *resource.Resource) (*sdktrace.Tr
)
return traceProvider, nil
}

func SetupMetrics(meter metric.Meter) {
var err error
ProfilesListSuccessCnt, err = meter.Int64Counter("elastic-package.profiles.list.success",
metric.WithDescription("The number of executions of profiles list finished successfully"),
metric.WithUnit("{profile}"))
if err != nil {
panic(err)
}
ProfilesListFailureCnt, err = meter.Int64Counter("elastic-package.profiles.list.failure",
metric.WithDescription("The number of executions of profiles list finished with failure"),
metric.WithUnit("{profile}"))
if err != nil {
panic(err)
}
}

0 comments on commit 0c1fb9d

Please sign in to comment.