mirror of
https://github.com/NotAShelf/watchdog.git
synced 2026-03-07 13:56:01 +00:00
internal/api: better multi-sites support; validate events against allowed domains
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Iff1ced4966b4d42cfd6dfefb0cfd97696a6a6964
This commit is contained in:
parent
16ace569a0
commit
18fe1a8234
10 changed files with 542 additions and 35 deletions
|
|
@ -43,6 +43,10 @@ func NewMetricsAggregator(pathRegistry *PathRegistry, eventRegistry *CustomEvent
|
|||
labels = append(labels, "referrer")
|
||||
}
|
||||
|
||||
if cfg.Site.Collect.Domain {
|
||||
labels = append(labels, "domain")
|
||||
}
|
||||
|
||||
pageviews := prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "web_pageviews_total",
|
||||
|
|
@ -143,7 +147,7 @@ func sanitizeLabel(label string) string {
|
|||
}
|
||||
|
||||
// Records a pageview with the configured dimensions
|
||||
func (m *MetricsAggregator) RecordPageview(path, country, device, referrer string) {
|
||||
func (m *MetricsAggregator) RecordPageview(path, country, device, referrer, domain string) {
|
||||
// Build label values in the same order as label names
|
||||
labels := prometheus.Labels{"path": sanitizeLabel(path)}
|
||||
|
||||
|
|
@ -159,6 +163,10 @@ func (m *MetricsAggregator) RecordPageview(path, country, device, referrer strin
|
|||
labels["referrer"] = sanitizeLabel(referrer)
|
||||
}
|
||||
|
||||
if m.cfg.Site.Collect.Domain {
|
||||
labels["domain"] = sanitizeLabel(domain)
|
||||
}
|
||||
|
||||
m.pageviews.With(labels).Inc()
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +201,7 @@ func (m *MetricsAggregator) AddUnique(ip, userAgent string) {
|
|||
}
|
||||
|
||||
m.estimator.Add(ip, userAgent)
|
||||
// Note: Gauge is updated in background goroutine, not here
|
||||
// NOTE: Gauge is updated in background goroutine, not here
|
||||
}
|
||||
|
||||
// Registers all metrics with the provided Prometheus registry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue