diff --git a/bin/slash/main.go b/bin/slash/main.go index 1933f89..3cb41f5 100644 --- a/bin/slash/main.go +++ b/bin/slash/main.go @@ -14,7 +14,6 @@ import ( "github.com/yourselfhosted/slash/server" "github.com/yourselfhosted/slash/server/common" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/profile" "github.com/yourselfhosted/slash/store" "github.com/yourselfhosted/slash/store/db" @@ -67,11 +66,6 @@ var ( return } - if serverProfile.Metric { - // nolint - metric.NewMetricClient(s.Secret, *serverProfile) - } - c := make(chan os.Signal, 1) // Trigger graceful shutdown on SIGINT or SIGTERM. // The default signal sent by the `kill` command is SIGTERM, diff --git a/go.mod b/go.mod index 861b9a0..b52606f 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,6 @@ require ( github.com/mssola/useragent v1.0.0 github.com/nyaruka/phonenumbers v1.4.0 github.com/pkg/errors v0.9.1 - github.com/posthog/posthog-go v1.2.18 golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa golang.org/x/mod v0.20.0 golang.org/x/oauth2 v0.22.0 diff --git a/go.sum b/go.sum index 56f41f6..1fdf4e7 100644 --- a/go.sum +++ b/go.sum @@ -294,8 +294,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posthog/posthog-go v1.2.18 h1:2CBA0LOB0up+gon+xpeXuhFw69gZpjAYxQoBBGwiDWw= -github.com/posthog/posthog-go v1.2.18/go.mod h1:QjlpryJtfYLrZF2GUkAhejH4E7WlDbdKkvOi5hLmkdg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= diff --git a/server/metric/metric.go b/server/metric/metric.go deleted file mode 100644 index 608fff0..0000000 --- a/server/metric/metric.go +++ /dev/null @@ -1,51 +0,0 @@ -package metric - -import ( - "github.com/posthog/posthog-go" - - "github.com/yourselfhosted/slash/server/profile" -) - -const ( - PostHogAPIKey = "phc_YFEi1aqUBW9sX2KDzdvMtK43DNu0mkeoKMKc0EQum2t" -) - -var ( - client *MetricClient -) - -type MetricClient struct { - workspaceID string - profile *profile.Profile - phClient *posthog.Client -} - -func NewMetricClient(workspaceID string, profile profile.Profile) (*MetricClient, error) { - phClient, err := posthog.NewWithConfig(PostHogAPIKey, posthog.Config{ - Endpoint: "https://app.posthog.com", - }) - if err != nil { - return nil, err - } - client = &MetricClient{ - workspaceID: workspaceID, - profile: &profile, - phClient: &phClient, - } - return client, nil -} - -func Enqueue(event string) { - if client == nil { - return - } - if client.profile.Mode != "prod" { - return - } - - // nolint - (*client.phClient).Enqueue(posthog.Capture{ - DistinctId: `slash-` + client.workspaceID, - Event: event, - }) -} diff --git a/server/profile/profile.go b/server/profile/profile.go index 5da3f14..a7338d1 100644 --- a/server/profile/profile.go +++ b/server/profile/profile.go @@ -24,8 +24,6 @@ type Profile struct { Driver string // Version is the current version of server. Version string - // Metric indicate the metric collection is enabled or not. - Metric bool } func (p *Profile) IsDev() bool { diff --git a/server/route/api/v1/auth_service.go b/server/route/api/v1/auth_service.go index a574286..ad5d0d7 100644 --- a/server/route/api/v1/auth_service.go +++ b/server/route/api/v1/auth_service.go @@ -17,7 +17,6 @@ import ( "github.com/yourselfhosted/slash/plugin/idp/oauth2" v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" storepb "github.com/yourselfhosted/slash/proto/gen/store" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/service/license" "github.com/yourselfhosted/slash/store" ) @@ -53,7 +52,6 @@ func (s *APIV1Service) SignIn(ctx context.Context, request *v1pb.SignInRequest) if err := s.doSignIn(ctx, user, time.Now().Add(AccessTokenDuration)); err != nil { return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err)) } - metric.Enqueue("user sign in") return convertUserFromStore(user), nil } @@ -181,7 +179,6 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest) if err != nil { return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to create user, err: %s", err)) } - metric.Enqueue("user sign up") if err := s.doSignIn(ctx, user, time.Now().Add(AccessTokenDuration)); err != nil { return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err)) } diff --git a/server/route/api/v1/collection_service.go b/server/route/api/v1/collection_service.go index 9c99943..2e03005 100644 --- a/server/route/api/v1/collection_service.go +++ b/server/route/api/v1/collection_service.go @@ -11,7 +11,6 @@ import ( v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" storepb "github.com/yourselfhosted/slash/proto/gen/store" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/service/license" "github.com/yourselfhosted/slash/store" ) @@ -131,7 +130,6 @@ func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.Creat return nil, status.Errorf(codes.Internal, "failed to create collection, err: %v", err) } - metric.Enqueue("collection create") return convertCollectionFromStore(collection), nil } diff --git a/server/route/api/v1/shortcut_service.go b/server/route/api/v1/shortcut_service.go index 3f646b0..63c79bd 100644 --- a/server/route/api/v1/shortcut_service.go +++ b/server/route/api/v1/shortcut_service.go @@ -17,7 +17,6 @@ import ( v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" storepb "github.com/yourselfhosted/slash/proto/gen/store" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/service/license" "github.com/yourselfhosted/slash/store" ) @@ -175,7 +174,6 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateS if err != nil { return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err) } - metric.Enqueue("shortcut create") return composedShortcut, nil } @@ -322,7 +320,6 @@ func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.G browserMap[browserName]++ } - metric.Enqueue("shortcut analytics") response := &v1pb.GetShortcutAnalyticsResponse{ References: mapToAnalyticsSlice(referenceMap), Devices: mapToAnalyticsSlice(deviceMap), diff --git a/server/route/frontend/frontend.go b/server/route/frontend/frontend.go index 74f6c5f..d2d4cc6 100644 --- a/server/route/frontend/frontend.go +++ b/server/route/frontend/frontend.go @@ -17,7 +17,6 @@ import ( "github.com/yourselfhosted/slash/internal/util" storepb "github.com/yourselfhosted/slash/proto/gen/store" "github.com/yourselfhosted/slash/server/common" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/profile" "github.com/yourselfhosted/slash/store" ) @@ -96,7 +95,6 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) { if err := s.createShortcutViewActivity(ctx, c.Request(), shortcut); err != nil { slog.Warn("failed to create shortcut view activity", slog.String("error", err.Error())) } - metric.Enqueue("shortcut view") // Inject shortcut metadata into `index.html`. indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateShortcutMetadata(shortcut).String()) @@ -114,7 +112,6 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) { return c.HTML(http.StatusOK, rawIndexHTML) } - metric.Enqueue("collection view") // Inject collection metadata into `index.html`. indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateCollectionMetadata(collection).String()) return c.HTML(http.StatusOK, indexHTML) diff --git a/server/server.go b/server/server.go index 74d3e18..e57d1ce 100644 --- a/server/server.go +++ b/server/server.go @@ -13,7 +13,6 @@ import ( "github.com/pkg/errors" storepb "github.com/yourselfhosted/slash/proto/gen/store" - "github.com/yourselfhosted/slash/server/metric" "github.com/yourselfhosted/slash/server/profile" apiv1 "github.com/yourselfhosted/slash/server/route/api/v1" "github.com/yourselfhosted/slash/server/route/frontend" @@ -93,7 +92,6 @@ func (s *Server) Start(ctx context.Context) error { } }() - metric.Enqueue("server start") return s.e.Start(fmt.Sprintf(":%d", s.Profile.Port)) }