Skip to content

Commit

Permalink
chore: remove metric service
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Feb 24, 2024
1 parent 222d04f commit b0f52ad
Show file tree
Hide file tree
Showing 13 changed files with 1 addition and 96 deletions.
4 changes: 0 additions & 4 deletions api/v1/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/plugin/webhook"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -351,7 +350,6 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
}
metric.Enqueue("memo comment create")
if _, err := s.Store.CreateInbox(ctx, &store.Inbox{
SenderID: memo.CreatorID,
ReceiverID: relatedMemo.CreatorID,
Expand Down Expand Up @@ -410,7 +408,6 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
log.Warn("Failed to dispatch memo created webhook", zap.Error(err))
}

metric.Enqueue("memo create")
return c.JSON(http.StatusOK, memoResponse)
}

Expand Down Expand Up @@ -1011,7 +1008,6 @@ func (s *APIV1Service) dispatchMemoRelatedWebhook(ctx context.Context, memo *Mem
if err != nil {
return err
}
metric.Enqueue("webhook dispatch")
for _, hook := range webhooks {
payload := convertMemoToWebhookPayload(memo)
payload.ActivityType = activityType
Expand Down
3 changes: 0 additions & 3 deletions api/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/plugin/storage/s3"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -162,7 +161,6 @@ func (s *APIV1Service) CreateResource(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
}
metric.Enqueue("resource create")
return c.JSON(http.StatusOK, convertResourceFromStore(resource))
}

Expand Down Expand Up @@ -240,7 +238,6 @@ func (s *APIV1Service) UploadResource(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
}
metric.Enqueue("resource create")
return c.JSON(http.StatusOK, convertResourceFromStore(resource))
}

Expand Down
2 changes: 0 additions & 2 deletions api/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"golang.org/x/crypto/bcrypt"

"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -183,7 +182,6 @@ func (s *APIV1Service) CreateUser(c echo.Context) error {
}

userMessage := convertUserFromStore(user)
metric.Enqueue("user create")
return c.JSON(http.StatusOK, userMessage)
}

Expand Down
3 changes: 0 additions & 3 deletions api/v2/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/usememos/memos/plugin/idp"
"github.com/usememos/memos/plugin/idp/oauth2"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -168,7 +167,6 @@ func (s *APIV2Service) doSignIn(ctx context.Context, user *store.User, expireTim
return status.Errorf(codes.Internal, "failed to set grpc header, error: %v", err)
}

metric.Enqueue("user sign in")
return nil
}

Expand Down Expand Up @@ -214,7 +212,6 @@ func (s *APIV2Service) SignUp(ctx context.Context, request *apiv2pb.SignUpReques
if err := s.doSignIn(ctx, user, time.Now().Add(auth.AccessTokenDuration)); err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err))
}
metric.Enqueue("user sign up")
return &apiv2pb.SignUpResponse{
User: convertUserFromStore(user),
}, nil
Expand Down
4 changes: 0 additions & 4 deletions api/v2/memo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/usememos/memos/plugin/webhook"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -64,7 +63,6 @@ func (s *APIV2Service) CreateMemo(ctx context.Context, request *apiv2pb.CreateMe
if err != nil {
return nil, err
}
metric.Enqueue("memo create")

memoMessage, err := s.convertMemoFromStore(ctx, memo)
if err != nil {
Expand Down Expand Up @@ -371,7 +369,6 @@ func (s *APIV2Service) CreateMemoComment(ctx context.Context, request *apiv2pb.C
return nil, status.Errorf(codes.Internal, "failed to create inbox")
}
}
metric.Enqueue("memo comment create")

response := &apiv2pb.CreateMemoCommentResponse{
Memo: memo,
Expand Down Expand Up @@ -806,7 +803,6 @@ func (s *APIV2Service) dispatchMemoRelatedWebhook(ctx context.Context, memo *api
if err != nil {
return err
}
metric.Enqueue("webhook dispatch")
for _, hook := range webhooks {
payload := convertMemoToWebhookPayload(memo)
payload.ActivityType = activityType
Expand Down
2 changes: 0 additions & 2 deletions api/v2/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -46,7 +45,6 @@ func (s *APIV2Service) CreateResource(ctx context.Context, request *apiv2pb.Crea
return nil, status.Errorf(codes.Internal, "failed to create resource: %v", err)
}

metric.Enqueue("resource create")
return &apiv2pb.CreateResourceResponse{
Resource: s.convertResourceFromStore(ctx, resource),
}, nil
Expand Down
16 changes: 1 addition & 15 deletions bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/server"
_profile "github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store/db"
)
Expand All @@ -41,7 +40,6 @@ var (
driver string
dsn string
serveFrontend bool
enableMetric bool

rootCmd = &cobra.Command{
Use: "memos",
Expand Down Expand Up @@ -74,11 +72,6 @@ var (
return
}

if profile.Metric {
// nolint
metric.NewMetricClient(s.ID, *profile)
}

c := make(chan os.Signal, 1)
// Trigger graceful shutdown on SIGINT or SIGTERM.
// The default signal sent by the `kill` command is SIGTERM,
Expand Down Expand Up @@ -124,7 +117,6 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)")
rootCmd.PersistentFlags().BoolVarP(&serveFrontend, "frontend", "", true, "serve frontend files")
rootCmd.PersistentFlags().BoolVarP(&enableMetric, "metric", "", true, "allow metric collection")

err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
if err != nil {
Expand Down Expand Up @@ -154,17 +146,12 @@ func init() {
if err != nil {
panic(err)
}
err = viper.BindPFlag("metric", rootCmd.PersistentFlags().Lookup("metric"))
if err != nil {
panic(err)
}

viper.SetDefault("mode", "demo")
viper.SetDefault("driver", "sqlite")
viper.SetDefault("addr", "")
viper.SetDefault("port", 8081)
viper.SetDefault("frontend", true)
viper.SetDefault("metric", true)
viper.SetEnvPrefix("memos")
}

Expand All @@ -187,9 +174,8 @@ port: %d
mode: %s
driver: %s
frontend: %t
metric: %t
---
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Frontend, profile.Metric)
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Frontend)
}

func printGreetings() {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/posthog/posthog-go v0.0.0-20240208111551-abe6962c309e
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,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 v0.0.0-20240208111551-abe6962c309e h1:Cks+ATHSvyId+c4XOTdvVomE2Srb6WFlkXljYZddOEw=
github.com/posthog/posthog-go v0.0.0-20240208111551-abe6962c309e/go.mod h1:migYMxlAqcnQy+3eN8mcL0b2tpKy6R+8Zc0lxwk4dKM=
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=
Expand Down Expand Up @@ -460,7 +458,6 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
Expand Down
2 changes: 0 additions & 2 deletions server/integration/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/usememos/memos/plugin/telegram"
"github.com/usememos/memos/plugin/webhook"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -231,7 +230,6 @@ func (t *TelegramHandler) dispatchMemoRelatedWebhook(ctx context.Context, memo s
if err != nil {
return err
}
metric.Enqueue("webhook dispatch")
for _, hook := range webhooks {
payload := t.convertMemoToWebhookPayload(ctx, memo)
payload.ActivityType = activityType
Expand Down
2 changes: 0 additions & 2 deletions server/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type Profile struct {
Version string `json:"version"`
// Frontend indicate the frontend is enabled or not
Frontend bool `json:"-"`
// Metric indicate the metric collection is enabled or not
Metric bool `json:"-"`
}

func (p *Profile) IsDev() bool {
Expand Down
3 changes: 0 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/usememos/memos/server/frontend"
"github.com/usememos/memos/server/integration"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/service/metric"
versionchecker "github.com/usememos/memos/server/service/version_checker"
"github.com/usememos/memos/store"
)
Expand Down Expand Up @@ -106,8 +105,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
func (s *Server) Start(ctx context.Context) error {
go versionchecker.NewVersionChecker(s.Store, s.Profile).Start(ctx)
go s.telegramBot.Start(ctx)

metric.Enqueue("server start")
return s.e.Start(fmt.Sprintf("%s:%d", s.Profile.Addr, s.Profile.Port))
}

Expand Down
52 changes: 0 additions & 52 deletions server/service/metric/metric.go

This file was deleted.

0 comments on commit b0f52ad

Please sign in to comment.