chore: retire unused service

This commit is contained in:
Steven 2024-08-27 23:42:37 +08:00
parent 9d6d93ab39
commit 784d91ab75
10 changed files with 0 additions and 75 deletions

View File

@ -14,7 +14,6 @@ import (
"github.com/yourselfhosted/slash/server" "github.com/yourselfhosted/slash/server"
"github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/server/common"
"github.com/yourselfhosted/slash/server/metric"
"github.com/yourselfhosted/slash/server/profile" "github.com/yourselfhosted/slash/server/profile"
"github.com/yourselfhosted/slash/store" "github.com/yourselfhosted/slash/store"
"github.com/yourselfhosted/slash/store/db" "github.com/yourselfhosted/slash/store/db"
@ -67,11 +66,6 @@ var (
return return
} }
if serverProfile.Metric {
// nolint
metric.NewMetricClient(s.Secret, *serverProfile)
}
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
// Trigger graceful shutdown on SIGINT or SIGTERM. // Trigger graceful shutdown on SIGINT or SIGTERM.
// The default signal sent by the `kill` command is SIGTERM, // The default signal sent by the `kill` command is SIGTERM,

1
go.mod
View File

@ -74,7 +74,6 @@ require (
github.com/mssola/useragent v1.0.0 github.com/mssola/useragent v1.0.0
github.com/nyaruka/phonenumbers v1.4.0 github.com/nyaruka/phonenumbers v1.4.0
github.com/pkg/errors v0.9.1 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/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/mod v0.20.0 golang.org/x/mod v0.20.0
golang.org/x/oauth2 v0.22.0 golang.org/x/oauth2 v0.22.0

2
go.sum
View File

@ -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 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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/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.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 v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

View File

@ -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,
})
}

View File

@ -24,8 +24,6 @@ type Profile struct {
Driver string Driver string
// Version is the current version of server. // Version is the current version of server.
Version string Version string
// Metric indicate the metric collection is enabled or not.
Metric bool
} }
func (p *Profile) IsDev() bool { func (p *Profile) IsDev() bool {

View File

@ -17,7 +17,6 @@ import (
"github.com/yourselfhosted/slash/plugin/idp/oauth2" "github.com/yourselfhosted/slash/plugin/idp/oauth2"
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store" 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/server/service/license"
"github.com/yourselfhosted/slash/store" "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 { 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)) return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err))
} }
metric.Enqueue("user sign in")
return convertUserFromStore(user), nil return convertUserFromStore(user), nil
} }
@ -181,7 +179,6 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to create user, err: %s", err)) 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 { 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)) return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err))
} }

View File

@ -11,7 +11,6 @@ import (
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store" 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/server/service/license"
"github.com/yourselfhosted/slash/store" "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) return nil, status.Errorf(codes.Internal, "failed to create collection, err: %v", err)
} }
metric.Enqueue("collection create")
return convertCollectionFromStore(collection), nil return convertCollectionFromStore(collection), nil
} }

View File

@ -17,7 +17,6 @@ import (
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store" 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/server/service/license"
"github.com/yourselfhosted/slash/store" "github.com/yourselfhosted/slash/store"
) )
@ -175,7 +174,6 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateS
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err) return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
} }
metric.Enqueue("shortcut create")
return composedShortcut, nil return composedShortcut, nil
} }
@ -322,7 +320,6 @@ func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.G
browserMap[browserName]++ browserMap[browserName]++
} }
metric.Enqueue("shortcut analytics")
response := &v1pb.GetShortcutAnalyticsResponse{ response := &v1pb.GetShortcutAnalyticsResponse{
References: mapToAnalyticsSlice(referenceMap), References: mapToAnalyticsSlice(referenceMap),
Devices: mapToAnalyticsSlice(deviceMap), Devices: mapToAnalyticsSlice(deviceMap),

View File

@ -17,7 +17,6 @@ import (
"github.com/yourselfhosted/slash/internal/util" "github.com/yourselfhosted/slash/internal/util"
storepb "github.com/yourselfhosted/slash/proto/gen/store" storepb "github.com/yourselfhosted/slash/proto/gen/store"
"github.com/yourselfhosted/slash/server/common" "github.com/yourselfhosted/slash/server/common"
"github.com/yourselfhosted/slash/server/metric"
"github.com/yourselfhosted/slash/server/profile" "github.com/yourselfhosted/slash/server/profile"
"github.com/yourselfhosted/slash/store" "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 { if err := s.createShortcutViewActivity(ctx, c.Request(), shortcut); err != nil {
slog.Warn("failed to create shortcut view activity", slog.String("error", err.Error())) slog.Warn("failed to create shortcut view activity", slog.String("error", err.Error()))
} }
metric.Enqueue("shortcut view")
// Inject shortcut metadata into `index.html`. // Inject shortcut metadata into `index.html`.
indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateShortcutMetadata(shortcut).String()) 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) return c.HTML(http.StatusOK, rawIndexHTML)
} }
metric.Enqueue("collection view")
// Inject collection metadata into `index.html`. // Inject collection metadata into `index.html`.
indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateCollectionMetadata(collection).String()) indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateCollectionMetadata(collection).String())
return c.HTML(http.StatusOK, indexHTML) return c.HTML(http.StatusOK, indexHTML)

View File

@ -13,7 +13,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
storepb "github.com/yourselfhosted/slash/proto/gen/store" storepb "github.com/yourselfhosted/slash/proto/gen/store"
"github.com/yourselfhosted/slash/server/metric"
"github.com/yourselfhosted/slash/server/profile" "github.com/yourselfhosted/slash/server/profile"
apiv1 "github.com/yourselfhosted/slash/server/route/api/v1" apiv1 "github.com/yourselfhosted/slash/server/route/api/v1"
"github.com/yourselfhosted/slash/server/route/frontend" "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)) return s.e.Start(fmt.Sprintf(":%d", s.Profile.Port))
} }