Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/atd log adapter #3894

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/mile-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Mile Build
run-name: Mile Build triggered by ${{ github.actor }}

on:
pull_request:
branches: [ "main" ]

workflow_call:
inputs:
# deployTarget:
# required: true
# default: staging
# type: string
gitTag:
required: true
type: string

workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3

# - name: Install GoLang
# uses: actions/setup-go@v3
# with:
# go-version: '>=1.22.0'

# - name: Deployment target
# env:
# DEPLOY_TARGET: staging
# run: |
# echo "Received input: ${{ github.event.inputs.deployTarget }}"
#
# if [ ! -z "${{ github.event.inputs.deployTarget }}" ]; then
# DEPLOY_TARGET=${{ github.event.inputs.deployTarget }}
# fi
# echo "Using environment...${DEPLOY_TARGET}"
# echo "DEPLOY_TARGET=${DEPLOY_TARGET}" >> $GITHUB_ENV
#
# shell: bash

# - name: Set Git Tag
# run: |
# echo "GIT_TAG=${{ github.event.inputs.gitTag }}" >> $GITHUB_ENV

- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Log in to DO Container Registry
run: doctl registry login --expiry-seconds 1200

# - name: Save DigitalOcean kubeconfig
# run: |
# if [ ${DEPLOY_TARGET} == 'prod' ]; then
# doctl kubernetes cluster kubeconfig save dhi-prod
# elif [ ${DEPLOY_TARGET} == 'staging' ]; then
# doctl kubernetes cluster kubeconfig save atd-dev
# else
# echo "is neither MAIN nor staging branch"
# fi
# shell: bash

- name: Build with Make
run: make milebuild
# cd ./prebid-setup && git clone https://github.com/prebid/prebid-server.git -b $GIT_TAG &&
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ format:
# formatcheck runs format for diagnostics, without modifying the code
formatcheck:
./scripts/format.sh -f false


VERSION:=$(shell date +%Y%m%d%H%M%S)

# Use the GIT_TAG passed from the GitHub Actions workflow
PREBID_TAG=registry.digitalocean.com/automatad/amp/prebid-server:$(VERSION)

# .PHONY: build

buildmile:
docker build -t $(PREBID_TAG) .
docker push $(PREBID_TAG)
28 changes: 28 additions & 0 deletions analytics/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package build

import (
"encoding/json"
"fmt"
"github.com/prebid/prebid-server/v2/analytics/mile"

"github.com/benbjohnson/clock"
"github.com/golang/glog"
Expand Down Expand Up @@ -56,6 +58,32 @@ func New(analytics *config.Analytics) analytics.Runner {
}
}

if analytics.Mile.Enabled {
mileConfig := mile.BuildConfig(analytics.Mile.Scope,
analytics.Mile.Endpoint, "auction")

fmt.Println(mileConfig)

mileModule, err := mile.NewModuleWithConfig(
clients.GetDefaultHttpInstance(),
analytics.Mile.Scope,
analytics.Mile.Endpoint,
mileConfig,
1,
"100",
"5s",
clock.New(),
)
fmt.Println(mileModule)

if err == nil {
modules["mile"] = mileModule
} else {
glog.Errorf("Could not initialize MileModule: %v", err)

}
}

return modules
}

Expand Down
91 changes: 91 additions & 0 deletions analytics/mile/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package mile

import (
"encoding/json"
"net/http"
"net/url"
"time"

"github.com/docker/go-units"
)

func BuildConfig(scope, endpoint string, features ...string) *Configuration {

config := Configuration{
ScopeID: scope,
Endpoint: endpoint,
Features: map[string]bool{
auction: false,
video: false,
amp: false,
cookieSync: false,
setUID: false,
},
}
for _, feature := range features {
config.Features[feature] = true
}
return &config
}

func fetchConfig(client *http.Client, endpoint *url.URL) (*Configuration, error) {
res, err := client.Get(endpoint.String())
if err != nil {
return nil, err
}

defer res.Body.Close()
c := Configuration{}
err = json.NewDecoder(res.Body).Decode(&c)
if err != nil {
return nil, err
}
return &c, nil
}

func newBufferConfig(count int, size, duration string) (*bufferConfig, error) {
pDuration, err := time.ParseDuration(duration)
if err != nil {
return nil, err
}
pSize, err := units.FromHumanSize(size)
if err != nil {
return nil, err
}
return &bufferConfig{
pDuration,
int64(count),
pSize,
}, nil
}

func (a *Configuration) isSameAs(b *Configuration) bool {
sameEndpoint := a.Endpoint == b.Endpoint
sameScopeID := a.ScopeID == b.ScopeID
sameFeature := len(a.Features) == len(b.Features)
for key := range a.Features {
sameFeature = sameFeature && a.Features[key] == b.Features[key]
}
return sameFeature && sameEndpoint && sameScopeID
}

func (a *Configuration) clone() *Configuration {
c := &Configuration{
ScopeID: a.ScopeID,
Endpoint: a.Endpoint,
Features: make(map[string]bool, len(a.Features)),
}

for k, v := range a.Features {
c.Features[k] = v
}

return c
}

func (a *Configuration) disableAllFeatures() *Configuration {
for k := range a.Features {
a.Features[k] = false
}
return a
}
61 changes: 61 additions & 0 deletions analytics/mile/configupdate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mile

import (
"fmt"
"net/http"
"net/url"
"time"

"github.com/prebid/prebid-server/v2/util/task"
)

// ConfigUpdateTask publishes configurations until the stop channel is signaled.
type ConfigUpdateTask interface {
Start(stop <-chan struct{}) <-chan *Configuration
}

// ConfigUpdateHttpTask polls an HTTP endpoint on a specified interval and publishes configurations until
// the stop channel is signaled.
type ConfigUpdateHttpTask struct {
task *task.TickerTask
configChan chan *Configuration
}

func NewConfigUpdateHttpTask(httpClient *http.Client, scope, endpoint, refreshInterval string) (*ConfigUpdateHttpTask, error) {
refreshDuration, err := time.ParseDuration(refreshInterval)
if err != nil {
return nil, fmt.Errorf("fail to parse the module args, arg=analytics.pubstack.configuration_refresh_delay: %v", err)
}

endpointUrl, err := url.Parse(endpoint + "/bootstrap?scopeId=" + scope)
if err != nil {
return nil, err
}

configChan := make(chan *Configuration)

tr := task.NewTickerTaskFromFunc(refreshDuration, func() error {
config, err := fetchConfig(httpClient, endpointUrl)
if err != nil {
return fmt.Errorf("[pubstack] Fail to fetch remote configuration: %v", err)
}
configChan <- config
return nil
})

return &ConfigUpdateHttpTask{
task: tr,
configChan: configChan,
}, nil
}

func (t *ConfigUpdateHttpTask) Start(stop <-chan struct{}) <-chan *Configuration {
go t.task.Start()

go func() {
<-stop
t.task.Stop()
}()

return t.configChan
}
Loading