Skip to content

🎧 Your Personal Streaming Service

fix(insights): better status

Deluan6bc4c0317f02
diff --git a/core/metrics/insights.go b/core/metrics/insights.go
index 97e088671..8a4b1a6d4 100644
--- a/core/metrics/insights.go
+++ b/core/metrics/insights.go
@@ -10,6 +10,7 @@ import (
"runtime"
"runtime/debug"
"sync"
+ "sync/atomic"
"time"
"github.com/Masterminds/squirrel"
@@ -34,8 +35,8 @@ var (
type insightsCollector struct {
ds model.DataStore
- lastRun time.Time
- lastStatus bool
+ lastRun atomic.Int64
+ lastStatus atomic.Bool
}
func GetInstance(ds model.DataStore) Insights {
@@ -68,7 +69,8 @@ func (c *insightsCollector) Run(ctx context.Context) {
}
func (c *insightsCollector) LastRun(context.Context) (timestamp time.Time, success bool) {
- return c.lastRun, c.lastStatus
+ t := c.lastRun.Load()
+ return time.UnixMilli(t), c.lastStatus.Load()
}
func (c *insightsCollector) sendInsights(ctx context.Context) {
@@ -102,8 +104,8 @@ func (c *insightsCollector) sendInsights(ctx context.Context) {
}
log.Info(ctx, "Sent Insights data (for details see http://navidrome.org/docs/getting-started/insights", "data",
string(data), "server", consts.InsightsEndpoint, "status", resp.Status)
- c.lastRun = time.Now()
- c.lastStatus = resp.StatusCode < 300
+ c.lastRun.Store(time.Now().UnixMilli())
+ c.lastStatus.Store(resp.StatusCode < 300)
resp.Body.Close()
}
diff --git a/core/metrics/insights/data.go b/core/metrics/insights/data.go
index 576bbd316..0cf7b0411 100644
--- a/core/metrics/insights/data.go
+++ b/core/metrics/insights/data.go
@@ -36,7 +36,7 @@ type Data struct {
Shares int64 `json:"shares"`
Radios int64 `json:"radios"`
ActiveUsers int64 `json:"activeUsers"`
- ActivePlayers map[string]int64 `json:"activePlayers"`
+ ActivePlayers map[string]int64 `json:"activePlayers,omitempty"`
} `json:"library"`
Config struct {
LogLevel string `json:"logLevel,omitempty"`
diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json
index 858f750ee..774cb0d1c 100644
--- a/resources/i18n/pt.json
+++ b/resources/i18n/pt.json
@@ -436,7 +436,11 @@
"homepage": "Website",
"source": "Código fonte",
"featureRequests": "Solicitar funcionalidade",
- "lastInsightsCollection": "Última coleta de dados"
+ "lastInsightsCollection": "Última coleta de dados",
+ "insights": {
+ "disabled": "Desligado",
+ "waiting": "Aguardando"
+ }
}
},
"activity": {
diff --git a/ui/src/dialogs/AboutDialog.jsx b/ui/src/dialogs/AboutDialog.jsx
index baee011ca..ca9db79d7 100644
--- a/ui/src/dialogs/AboutDialog.jsx
+++ b/ui/src/dialogs/AboutDialog.jsx
@@ -55,6 +55,16 @@ const AboutDialog = ({ open, onClose }) => {
const { permissions } = usePermissions()
const { data, loading } = useGetOne('insights', 'insights_status')
+ const lastRun = !loading && data?.lastRun
+ let insightsStatus = 'N/A'
+ if (lastRun === 'disabled') {
+ insightsStatus = translate('about.links.insights.disabled')
+ } else if (lastRun && lastRun?.startsWith('1969-12-31')) {
+ insightsStatus = translate('about.links.insights.waiting')
+ } else if (lastRun) {
+ insightsStatus = lastRun
+ }
+
return (
<Dialog onClose={onClose} aria-labelledby="about-dialog-title" open={open}>
<DialogTitle id="about-dialog-title" onClose={onClose}>
@@ -97,9 +107,7 @@ const AboutDialog = ({ open, onClose }) => {
{translate(`about.links.lastInsightsCollection`)}:
</TableCell>
<TableCell align="left">
- <Link href={INSIGHTS_DOC_URL}>
- {(!loading && data?.lastRun) || 'N/A'}{' '}
- </Link>
+ <Link href={INSIGHTS_DOC_URL}>{insightsStatus}</Link>
</TableCell>
</TableRow>
) : null}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 178977c7c..75c5e12e5 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -438,7 +438,11 @@
"homepage": "Home page",
"source": "Source code",
"featureRequests": "Feature requests",
- "lastInsightsCollection": "Last insights collection"
+ "lastInsightsCollection": "Last insights collection",
+ "insights": {
+ "disabled": "Disabled",
+ "waiting": "Waiting"
+ }
}
},
"activity": {