Skip to content

Conversation

@przemkaczmarek
Copy link
Collaborator

@przemkaczmarek przemkaczmarek commented Jul 29, 2025

Implements the first part of #3809

@bsardo bsardo marked this pull request as draft July 29, 2025 15:10
@przemkaczmarek przemkaczmarek force-pushed the feature/account-analytics branch from 478fb7d to 6ae59c9 Compare August 8, 2025 12:47
@bsardo bsardo changed the title Configure analytics adapters per account #3809 Configure analytics adapters per account Aug 26, 2025
@bsardo bsardo changed the title Configure analytics adapters per account Analytics: Configure per account Aug 26, 2025
@bsardo bsardo self-assigned this Aug 26, 2025
@przemkaczmarek przemkaczmarek force-pushed the feature/account-analytics branch from bb7db0c to c47be0f Compare October 2, 2025 19:17
)

// builders returns mapping between analytics module name and its builder.
// Since we no longer use vendor directories, we hardcode "modules" instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the second comment.

router/router.go Outdated
shutdown, fetcher, ampFetcher, accounts, categoriesFetcher, videoFetcher, storedRespFetcher := storedRequestsConf.NewStoredRequests(cfg, r.MetricsEngine, generalHttpClient, r.Router)

analyticsRunner := analyticsBuild.New(&cfg.Analytics)
analyticsRunner := analyticsBuild.New(map[string]interface{}{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter here needs to be &cfg.Analytics.

Makefile Outdated

# build-analytics generates analytics/builder.go file which provides a list of all available analytics modules
build-analytics:
go generate analytics/modules.go
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be analytics/build/build.go.

Comment on lines 13 to 20
Enabled bool `mapstructure:"enabled" json:"enabled"`
Endpoint config.AgmaAnalyticsHttpEndpoint `mapstructure:"endpoint" json:"endpoint"`
Buffers struct {
EventCount int `mapstructure:"eventCount" json:"eventCount"`
BufferSize string `mapstructure:"bufferSize" json:"bufferSize"`
Timeout string `mapstructure:"timeout" json:"timeout"`
} `mapstructure:"buffers" json:"buffers"`
Accounts []config.AgmaAnalyticsAccount `mapstructure:"accounts" json:"accounts"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all of the mapstructure annotations. Make this same change for the other modules (pubstack and filelogger).


var c Config
if cfg != nil {
if err := mapstructure.Decode(cfg, &c); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to jsonutil.Unmarshal since the data is passed in as JSON (make the same change for the other modules).

@@ -1,4 +1,4 @@
package filesystem
package filelogger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. We will change the folder name, the package name and update the template to refer to this as file so it matches the config and does not become a breaking change.

// Config is the minimal configuration for the file logger analytics module.
// Empty Filename means the module is disabled.
type Config struct {
Enabled bool `json:"enabled"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did enabled exist before for file logger? If not, we should remove it and just rely on the presence of a filename in the config indicating that we want to enable this module.

CurrencyConverter CurrencyConverter `mapstructure:"currency_converter"`
DefReqConfig DefReqConfig `mapstructure:"default_request"`
MaxRequestSize int64 `mapstructure:"max_request_size"`
Analytics map[string]interface{} `mapstructure:"analytics"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the agma, pubstack and filelogger configs belong in their corresponding packages now because this is now a generic map for analytics module configurations.

Comment on lines 236 to 247
agmaMap, _ := cfg.Analytics["agma"].(map[string]interface{})
endpointMap, _ := agmaMap["endpoint"].(map[string]interface{})
buffersMap, _ := agmaMap["buffers"].(map[string]interface{})
cmpBools(t, "analytics.agma.enabled", false, agmaMap["enabled"].(bool))
cmpStrings(t, "analytics.agma.endpoint.timeout", "2s", endpointMap["timeout"].(string))
cmpBools(t, "analytics.agma.endpoint.gzip", false, endpointMap["gzip"].(bool))
cmpStrings(t, "analytics.agma.endppoint.url", "https://go.pbs.agma-analytics.de/v1/prebid-server", endpointMap["url"].(string))
cmpStrings(t, "analytics.agma.buffers.size", "2MB", buffersMap["size"].(string))
cmpInts(t, "analytics.agma.buffers.count", 100, buffersMap["count"].(int))
cmpStrings(t, "analytics.agma.buffers.timeout", "15m", buffersMap["timeout"].(string))
accountsSlice, _ := agmaMap["accounts"].([]interface{})
cmpInts(t, "analytics.agma.accounts", 0, len(accountsSlice))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this and any other config checks for filelogger and pubstack since they are now the concern on the individual module packages due to the type change in config/config.go.

shutdown, fetcher, ampFetcher, accounts, categoriesFetcher, videoFetcher, storedRespFetcher := storedRequestsConf.NewStoredRequests(cfg, r.MetricsEngine, generalHttpClient, r.Router)

analyticsRunner := analyticsBuild.New(&cfg.Analytics)
analyticsRunner := analyticsBuild.New(cfg.Analytics)
Copy link
Collaborator

@bsardo bsardo Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this no longer a pointer? cfg.Analytics could be nil if there aren't any analytics modules enabled.
Discussed offline. This should be ok as is.

return nil, nil
}

full := config.AgmaAnalytics{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All config structs for each analytics adapter should be defined in their corresponding module.go.

Copy link
Collaborator

@bsardo bsardo Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add analytics/modules/agma/module_test.go
See modules/fiftyonedegrees/devicedetection/module_test.go as an example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add analytics/modules/file/module_test.go

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add analytics/modules/pubstack/module_test.go

@bsardo bsardo marked this pull request as ready for review November 20, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants