Skip to content

Commit

Permalink
feat: removed statsd related code and references (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Mayur Jagtap <[email protected]>
  • Loading branch information
Mayurjag and solsticemj25 authored Oct 23, 2023
1 parent 01a40d6 commit 859dde6
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 607 deletions.
4 changes: 0 additions & 4 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
esStore "github.com/goto/compass/internal/store/elasticsearch"
"github.com/goto/compass/internal/store/postgres"
"github.com/goto/compass/internal/workermanager"
"github.com/goto/compass/pkg/statsd"
"github.com/goto/compass/pkg/telemetry"
"github.com/goto/salt/cmdx"
"github.com/goto/salt/config"
Expand Down Expand Up @@ -83,9 +82,6 @@ type Config struct {
// OpenTelemetry and Newrelic
Telemetry telemetry.Config `mapstructure:"telemetry"`

// StatsD
StatsD statsd.Config `mapstructure:"statsd"`

// Deprecated: Use Config.Telemetry instead
NewRelic telemetry.NewRelicConfig `mapstructure:"newrelic"`

Expand Down
9 changes: 1 addition & 8 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
esStore "github.com/goto/compass/internal/store/elasticsearch"
"github.com/goto/compass/internal/store/postgres"
"github.com/goto/compass/internal/workermanager"
"github.com/goto/compass/pkg/statsd"
"github.com/goto/compass/pkg/telemetry"
"github.com/goto/salt/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -94,11 +93,6 @@ func runServer(ctx context.Context, cfg *Config) error {

defer cleanUp()

statsdReporter, err := statsd.Init(logger, cfg.StatsD)
if err != nil {
return err
}

esClient, err := initElasticsearch(logger, cfg.Elasticsearch)
if err != nil {
return err
Expand Down Expand Up @@ -126,7 +120,7 @@ func runServer(ctx context.Context, cfg *Config) error {
if err != nil {
return fmt.Errorf("create new user repository: %w", err)
}
userService := user.NewService(logger, userRepository, user.ServiceWithStatsDReporter(statsdReporter))
userService := user.NewService(logger, userRepository)

assetRepository, err := postgres.NewAssetRepository(pgClient, userRepository, 0, cfg.Service.Identity.ProviderDefaultName)
if err != nil {
Expand Down Expand Up @@ -180,7 +174,6 @@ func runServer(ctx context.Context, cfg *Config) error {
logger,
pgClient,
nrApp,
statsdReporter,
assetService,
starService,
discussionService,
Expand Down
5 changes: 0 additions & 5 deletions compass.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ telemetry:
# 1 means always.
trace_sample_probability: 1

statsd:
enabled: false
address: 127.0.0.1:8125
prefix: compass

newrelic:
enabled: false
licensekey: ____LICENSE_STRING_OF_40_CHARACTERS_____
Expand Down
28 changes: 2 additions & 26 deletions core/user/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"context"
"errors"

"github.com/goto/compass/pkg/statsd"
"github.com/goto/salt/log"
)

// Service is a type of service that manages business process
type Service struct {
statsdReporter *statsd.Reporter
repository Repository
logger log.Logger
repository Repository
logger log.Logger
}

// ValidateUser checks if user uuid is already in DB
Expand All @@ -25,14 +23,8 @@ func (s *Service) ValidateUser(ctx context.Context, uuid, email string) (string,
usr, err := s.repository.GetByUUID(ctx, uuid)
if err == nil {
if usr.ID != "" {
s.statsdReporter.Incr("user_stats").
Tag("info", "existing").
Publish()
return usr.ID, nil
}
s.statsdReporter.Incr("user_stats").
Tag("info", "error").
Publish()
err := errors.New("fetched user uuid from DB is empty")
s.logger.Error(err.Error())
return "", err
Expand All @@ -43,15 +35,9 @@ func (s *Service) ValidateUser(ctx context.Context, uuid, email string) (string,
Email: email,
})
if err != nil {
s.statsdReporter.Incr("user_stats").
Tag("info", "error").
Publish()
s.logger.Error("error when UpsertByEmail in ValidateUser service", "err", err.Error())
return "", err
}
s.statsdReporter.Incr("user_stats").
Tag("info", "new").
Publish()
return uid, nil
}

Expand All @@ -66,15 +52,5 @@ func NewService(logger log.Logger, repository Repository, opts ...func(*Service)
opt(s)
}

if s.statsdReporter == nil {
s.statsdReporter = &statsd.Reporter{}
}

return s
}

func ServiceWithStatsDReporter(statsdReporter *statsd.Reporter) func(*Service) {
return func(s *Service) {
s.statsdReporter = statsdReporter
}
}
9 changes: 0 additions & 9 deletions core/user/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/goto/compass/core/user"
"github.com/goto/compass/core/user/mocks"
"github.com/goto/compass/pkg/statsd"
"github.com/goto/salt/log"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -93,11 +92,3 @@ func TestValidateUser(t *testing.T) {
})
}
}

func TestServiceWithStatsDResporter(t *testing.T) {
t.Run("should create statsDReport for a service", func(t *testing.T) {
usr := &user.Service{}
s := user.ServiceWithStatsDReporter(&statsd.Reporter{})
s(usr)
})
}
3 changes: 0 additions & 3 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,12 @@ app:
COMPASS_SERVICE_PORT: 8080
COMPASS_SERVICE_GRPC_PORT: 8081
# COMPASS_SERVICE_HOST: 0.0.0.0
# COMPASS_STATSD_ENABLED: false
# COMPASS_STATSD_PREFIX: compass
# COMPASS_NEWRELIC_ENABLED: false
# COMPASS_NEWRELIC_APPNAME: compass
# COMPASS_LOG_LEVEL: info

secretConfig: {}
# COMPASS_ELASTICSEARCH_BROKERS: ~
# COMPASS_STATSD_ADDRESS: ~
# COMPASS_NEWRELIC_LICENSEKEY: ~
# COMPASS_DB_HOST: ~
# COMPASS_DB_PORT: 5432
Expand Down
13 changes: 2 additions & 11 deletions docs/docs/guides/telemetry.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# Telemetry

Compass collects basic HTTP metrics (response time, duration, etc) and sends it to [statsd](https://github.com/statsd/statsd) and [New Relic](https://newrelic.com/) when enabled.

## Statsd
By default statsd is not enabled. To enable statsd, we just need to set these configurations below

```
STATSD_ENABLED=true
STATSD_ADDRESS=127.0.0.1:8125
STATSD_PREFIX=compass
```
Compass collects basic HTTP metrics (response time, duration, etc) and sends it to [New Relic](https://newrelic.com/) when enabled.


## New Relic
Similar with statsd, New Relic is not enabled by default. To enable New Relic, you can set these configurations
New Relic is not enabled by default. To enable New Relic, you can set these configurations

```
NEW_RELIC_LICENSE_KEY=mf9d13c838u252252c43ji47q1u4ynzpDDDDTSPQ
Expand Down
20 changes: 0 additions & 20 deletions docs/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,6 @@ Compass's required variables to start using it.

Variables for metrics gathering.

### `STATSD_ADDRESS`

* Example value: `127.0.0.1:8125`
* Type: `optional`
* statsd client to send metrics to.

### `STATSD_PREFIX`

* Example value: `discovery`
* Type: `optional`
* Default: `compassApi`
* Prefix for statsd metrics names.

### `STATSD_ENABLED`

* Example value: `true`
* Type: `required`
* Default: `false`
* Enable publishing application metrics to statsd.

### `NEW_RELIC_APP_NAME`

* Example value: `compass-integration`
Expand Down
4 changes: 0 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
handlersv1beta1 "github.com/goto/compass/internal/server/v1beta1"
"github.com/goto/compass/internal/store/postgres"
"github.com/goto/compass/pkg/grpc_interceptor"
"github.com/goto/compass/pkg/statsd"
compassv1beta1 "github.com/goto/compass/proto/gotocompany/compass/v1beta1"
"github.com/goto/salt/log"
"github.com/goto/salt/mux"
Expand Down Expand Up @@ -67,7 +66,6 @@ func Serve(
logger *log.Logrus,
pgClient *postgres.Client,
nrApp *newrelic.Application,
statsdReporter *statsd.Reporter,
assetService handlersv1beta1.AssetService,
starService handlersv1beta1.StarService,
discussionService handlersv1beta1.DiscussionService,
Expand All @@ -83,7 +81,6 @@ func Serve(
TagTemplateSvc: tagTemplateService,
UserSvc: userService,
Logger: logger,
StatsD: statsdReporter,
})

healthHandler := health.NewHandler()
Expand All @@ -94,7 +91,6 @@ func Serve(
grpclogrus.UnaryServerInterceptor(logger.Entry()),
otelgrpc.UnaryServerInterceptor(),
nrgrpc.UnaryServerInterceptor(nrApp),
grpc_interceptor.StatsD(statsdReporter),
grpc_interceptor.UserHeaderCtx(config.Identity.HeaderKeyUUID, config.Identity.HeaderKeyEmail),
grpcctxtags.UnaryServerInterceptor(),
grpcrecovery.UnaryServerInterceptor(),
Expand Down
33 changes: 0 additions & 33 deletions internal/server/v1beta1/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/goto/compass/core/asset"
"github.com/goto/compass/core/star"
"github.com/goto/compass/core/user"
"github.com/goto/compass/pkg/statsd"
compassv1beta1 "github.com/goto/compass/proto/gotocompany/compass/v1beta1"
"github.com/r3labs/diff/v2"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -22,11 +21,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

//go:generate mockery --name=StatsDClient -r --case underscore --with-expecter --structname StatsDClient --filename statsd_monitor.go --output=./mocks
type StatsDClient interface {
Incr(name string) *statsd.Metric
}

type AssetService interface {
GetAllAssets(ctx context.Context, flt asset.Filter, withTotal bool) ([]asset.Asset, uint32, error)
GetAssetByID(ctx context.Context, id string) (asset.Asset, error)
Expand Down Expand Up @@ -304,12 +298,6 @@ func (server *APIServer) DeleteAsset(ctx context.Context, req *compassv1beta1.De
if errors.As(err, new(asset.NotFoundError)) {
return nil, status.Error(codes.NotFound, err.Error())
}
if errors.As(err, new(asset.DiscoveryError)) {
server.sendStatsDCounterMetric("discovery_error",
map[string]string{
"method": "delete",
})
}
return nil, internalServerError(server.logger, err.Error())
}

Expand Down Expand Up @@ -390,21 +378,10 @@ func (server *APIServer) upsertAsset(
switch {
case errors.As(err, new(asset.InvalidError)):
return "", status.Error(codes.InvalidArgument, err.Error())

case errors.As(err, new(asset.DiscoveryError)):
server.sendStatsDCounterMetric("discovery_error", map[string]string{
"method": mode,
})
}
return "", internalServerError(server.logger, err.Error())
}

server.sendStatsDCounterMetric(mode,
map[string]string{
"type": ast.Type.String(),
"service": ast.Service,
})

return assetID, nil
}

Expand All @@ -428,21 +405,11 @@ func (server *APIServer) upsertAssetWithoutLineage(ctx context.Context, ast asse
switch {
case errors.As(err, new(asset.InvalidError)):
return "", status.Error(codes.InvalidArgument, err.Error())

case errors.As(err, new(asset.DiscoveryError)):
server.sendStatsDCounterMetric("discovery_error",
map[string]string{
"method": mode,
})
}

return "", internalServerError(server.logger, err.Error())
}

server.sendStatsDCounterMetric(mode, map[string]string{
"type": ast.Type.String(),
"service": ast.Service,
})
return assetID, nil
}

Expand Down
11 changes: 5 additions & 6 deletions internal/server/v1beta1/mocks/asset_service.go

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

11 changes: 5 additions & 6 deletions internal/server/v1beta1/mocks/discussion_service.go

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

11 changes: 5 additions & 6 deletions internal/server/v1beta1/mocks/star_service.go

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

Loading

0 comments on commit 859dde6

Please sign in to comment.