Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: disable metrics collector (#580)

boojack85db6721deb5
diff --git a/bin/server/main.go b/bin/server/main.go
index b7fffd1a3..5157fc3a2 100644
--- a/bin/server/main.go
+++ b/bin/server/main.go
@@ -40,6 +40,8 @@ func run(profile *profile.Profile) error {
serverInstance.Store = storeInstance
metricCollector := server.NewMetricCollector(profile, storeInstance)
+ // Disable metrics collector.
+ metricCollector.Enabled = false
serverInstance.Collector = &metricCollector
println(greetingBanner)
diff --git a/server/metric_collector.go b/server/metric_collector.go
index 550db88c9..660625d4a 100644
--- a/server/metric_collector.go
+++ b/server/metric_collector.go
@@ -13,9 +13,10 @@ import (
// MetricCollector is the metric collector.
type MetricCollector struct {
- collector metric.Collector
- profile *profile.Profile
- store *store.Store
+ Collector metric.Collector
+ Enabled bool
+ Profile *profile.Profile
+ Store *store.Store
}
const (
@@ -26,23 +27,28 @@ func NewMetricCollector(profile *profile.Profile, store *store.Store) MetricColl
c := segment.NewCollector(segmentMetricWriteKey)
return MetricCollector{
- collector: c,
- profile: profile,
- store: store,
+ Collector: c,
+ Enabled: true,
+ Profile: profile,
+ Store: store,
}
}
func (mc *MetricCollector) Collect(_ context.Context, metric *metric.Metric) {
- if mc.profile.Mode == "dev" {
+ if !mc.Enabled {
+ return
+ }
+
+ if mc.Profile.Mode == "dev" {
return
}
if metric.Labels == nil {
metric.Labels = map[string]string{}
}
- metric.Labels["version"] = version.GetCurrentVersion(mc.profile.Mode)
+ metric.Labels["version"] = version.GetCurrentVersion(mc.Profile.Mode)
- err := mc.collector.Collect(metric)
+ err := mc.Collector.Collect(metric)
if err != nil {
fmt.Printf("Failed to request segment, error: %+v\n", err)
}