Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
a5df36ef
Commit
a5df36ef
authored
Oct 17, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update metrics
parent
e30d0c2d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
4 deletions
+72
-4
memo.go
api/v1/memo.go
+2
-0
user.go
api/v1/user.go
+2
-0
memos.go
cmd/memos.go
+4
-0
go.mod
go.mod
+1
-0
go.sum
go.sum
+4
-0
server.go
server/server.go
+5
-3
backup.go
server/service/backup/backup.go
+2
-1
metric.go
server/service/metric/metric.go
+52
-0
No files found.
api/v1/memo.go
View file @
a5df36ef
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/usememos/memos/common/log"
"github.com/usememos/memos/common/log"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -387,6 +388,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
...
@@ -387,6 +388,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
}
}
}
}
}
}
metric
.
Enqueue
(
"memo create"
)
return
c
.
JSON
(
http
.
StatusOK
,
memoResponse
)
return
c
.
JSON
(
http
.
StatusOK
,
memoResponse
)
}
}
...
...
api/v1/user.go
View file @
a5df36ef
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/bcrypt"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -169,6 +170,7 @@ func (s *APIV1Service) CreateUser(c echo.Context) error {
...
@@ -169,6 +170,7 @@ func (s *APIV1Service) CreateUser(c echo.Context) error {
if
err
:=
s
.
createUserCreateActivity
(
c
,
userMessage
);
err
!=
nil
{
if
err
:=
s
.
createUserCreateActivity
(
c
,
userMessage
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create activity"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create activity"
)
.
SetInternal
(
err
)
}
}
metric
.
Enqueue
(
"user create"
)
return
c
.
JSON
(
http
.
StatusOK
,
userMessage
)
return
c
.
JSON
(
http
.
StatusOK
,
userMessage
)
}
}
...
...
cmd/memos.go
View file @
a5df36ef
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"github.com/usememos/memos/common/log"
"github.com/usememos/memos/common/log"
"github.com/usememos/memos/server"
"github.com/usememos/memos/server"
_profile
"github.com/usememos/memos/server/profile"
_profile
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store/db"
"github.com/usememos/memos/store/db"
)
)
...
@@ -64,6 +65,9 @@ var (
...
@@ -64,6 +65,9 @@ var (
return
return
}
}
// nolint
metric
.
NewMetricClient
(
s
.
ID
,
*
profile
)
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,
...
...
go.mod
View file @
a5df36ef
...
@@ -106,6 +106,7 @@ require (
...
@@ -106,6 +106,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
...
...
go.sum
View file @
a5df36ef
...
@@ -284,6 +284,7 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S3
...
@@ -284,6 +284,7 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S3
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
...
@@ -474,6 +475,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
...
@@ -474,6 +475,8 @@ 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 v0.0.0-20230801140217-d607812dee69 h1:01dHVodha5BzrMtVmcpPeA4VYbZEsTXQ6m4123zQXJk=
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69/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.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=
...
@@ -573,6 +576,7 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
...
@@ -573,6 +576,7 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
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.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.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 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
...
...
server/server.go
View file @
a5df36ef
...
@@ -22,7 +22,8 @@ import (
...
@@ -22,7 +22,8 @@ import (
"github.com/usememos/memos/plugin/telegram"
"github.com/usememos/memos/plugin/telegram"
"github.com/usememos/memos/server/integration"
"github.com/usememos/memos/server/integration"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/server/service"
"github.com/usememos/memos/server/service/backup"
"github.com/usememos/memos/server/service/metric"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -38,7 +39,7 @@ type Server struct {
...
@@ -38,7 +39,7 @@ type Server struct {
apiV2Service
*
apiv2
.
APIV2Service
apiV2Service
*
apiv2
.
APIV2Service
// Asynchronous runners.
// Asynchronous runners.
backupRunner
*
service
.
BackupRunner
backupRunner
*
backup
.
BackupRunner
telegramBot
*
telegram
.
Bot
telegramBot
*
telegram
.
Bot
}
}
...
@@ -54,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
...
@@ -54,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
Profile
:
profile
,
Profile
:
profile
,
// Asynchronous runners.
// Asynchronous runners.
backupRunner
:
service
.
NewBackupRunner
(
store
),
backupRunner
:
backup
.
NewBackupRunner
(
store
),
telegramBot
:
telegram
.
NewBotWithHandler
(
integration
.
NewTelegramHandler
(
store
)),
telegramBot
:
telegram
.
NewBotWithHandler
(
integration
.
NewTelegramHandler
(
store
)),
}
}
...
@@ -132,6 +133,7 @@ func (s *Server) Start(ctx context.Context) error {
...
@@ -132,6 +133,7 @@ func (s *Server) Start(ctx context.Context) error {
}
}
}()
}()
metric
.
Enqueue
(
"server start"
)
return
s
.
e
.
Start
(
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
))
return
s
.
e
.
Start
(
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
))
}
}
...
...
server/service/backup.go
→
server/service/backup
/backup
.go
View file @
a5df36ef
package
service
package
backup
import
(
import
(
"context"
"context"
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
// nolint
type
BackupRunner
struct
{
type
BackupRunner
struct
{
Store
*
store
.
Store
Store
*
store
.
Store
}
}
...
...
server/service/metric/metric.go
0 → 100644
View file @
a5df36ef
package
metric
import
(
"github.com/posthog/posthog-go"
"github.com/usememos/memos/server/profile"
)
const
(
PostHogAPIKey
=
"phc_YFEi1aqUBW9sX2KDzdvMtK43DNu0mkeoKMKc0EQum2t"
)
var
(
client
*
MetricClient
)
// nolint
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
:
`memos-`
+
client
.
workspaceID
,
Event
:
event
,
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment