chore: format with golines
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I11a2f3273abf08c8cf02e0c335e26d826a6a6964
This commit is contained in:
parent
214c992494
commit
bf8390a916
5 changed files with 54 additions and 11 deletions
|
|
@ -47,7 +47,13 @@ func Run(configPath string) error {
|
||||||
metricsAgg.MustRegister(promRegistry)
|
metricsAgg.MustRegister(promRegistry)
|
||||||
|
|
||||||
// Create HTTP handlers
|
// Create HTTP handlers
|
||||||
ingestionHandler := api.NewIngestionHandler(*cfg, pathNormalizer, pathRegistry, refRegistry, metricsAgg)
|
ingestionHandler := api.NewIngestionHandler(
|
||||||
|
*cfg,
|
||||||
|
pathNormalizer,
|
||||||
|
pathRegistry,
|
||||||
|
refRegistry,
|
||||||
|
metricsAgg,
|
||||||
|
)
|
||||||
|
|
||||||
// Setup routes
|
// Setup routes
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
@ -58,7 +64,11 @@ func Run(configPath string) error {
|
||||||
})
|
})
|
||||||
|
|
||||||
if cfg.Security.MetricsAuth.Enabled {
|
if cfg.Security.MetricsAuth.Enabled {
|
||||||
metricsHandler = basicAuth(metricsHandler, cfg.Security.MetricsAuth.Username, cfg.Security.MetricsAuth.Password)
|
metricsHandler = basicAuth(
|
||||||
|
metricsHandler,
|
||||||
|
cfg.Security.MetricsAuth.Username,
|
||||||
|
cfg.Security.MetricsAuth.Password,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.Handle(cfg.Server.MetricsPath, metricsHandler)
|
mux.Handle(cfg.Server.MetricsPath, metricsHandler)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ type MetricsAggregator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new metrics aggregator with dynamic labels based on config
|
// Creates a new metrics aggregator with dynamic labels based on config
|
||||||
func NewMetricsAggregator(pathRegistry *PathRegistry, eventRegistry *CustomEventRegistry, cfg config.Config) *MetricsAggregator {
|
func NewMetricsAggregator(
|
||||||
|
pathRegistry *PathRegistry,
|
||||||
|
eventRegistry *CustomEventRegistry,
|
||||||
|
cfg config.Config,
|
||||||
|
) *MetricsAggregator {
|
||||||
// Build label names based on what's enabled in config
|
// Build label names based on what's enabled in config
|
||||||
labels := []string{"path"} // path is always included
|
labels := []string{"path"} // path is always included
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,11 @@ func TestUniquesEstimatorDailyRotation(t *testing.T) {
|
||||||
expectedSalt := DailySalt(time.Now())
|
expectedSalt := DailySalt(time.Now())
|
||||||
|
|
||||||
if currentSalt != expectedSalt {
|
if currentSalt != expectedSalt {
|
||||||
t.Errorf("Expected estimator to use current day's salt, got %s, expected %s", currentSalt, expectedSalt)
|
t.Errorf(
|
||||||
|
"Expected estimator to use current day's salt, got %s, expected %s",
|
||||||
|
currentSalt,
|
||||||
|
expectedSalt,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,11 @@ func TestIngestionHandler_Pageview(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
@ -80,7 +84,11 @@ func TestIngestionHandler_CustomEvent(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
@ -114,7 +122,11 @@ func TestIngestionHandler_WrongDomain(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
@ -144,7 +156,11 @@ func TestIngestionHandler_MethodNotAllowed(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
@ -171,7 +187,11 @@ func TestIngestionHandler_InvalidJSON(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
@ -206,7 +226,11 @@ func TestIngestionHandler_DeviceClassification(t *testing.T) {
|
||||||
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
|
||||||
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
|
||||||
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
|
||||||
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
|
metricsAgg := aggregate.NewMetricsAggregator(
|
||||||
|
pathRegistry,
|
||||||
|
aggregate.NewCustomEventRegistry(100),
|
||||||
|
cfg,
|
||||||
|
)
|
||||||
|
|
||||||
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,8 @@ func (c *Config) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate salt_rotation
|
// Validate salt_rotation
|
||||||
if c.Site.SaltRotation != "" && c.Site.SaltRotation != "daily" && c.Site.SaltRotation != "hourly" {
|
if c.Site.SaltRotation != "" && c.Site.SaltRotation != "daily" &&
|
||||||
|
c.Site.SaltRotation != "hourly" {
|
||||||
return fmt.Errorf("site.salt_rotation must be 'daily' or 'hourly'")
|
return fmt.Errorf("site.salt_rotation must be 'daily' or 'hourly'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue