Skip to content

Commit 636d140

Browse files
committed
rewrite addevents CLI using faker package
1 parent f6d0726 commit 636d140

File tree

14 files changed

+190
-587
lines changed

14 files changed

+190
-587
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ start/addevents: tmp/.env
3030
&& $(DOCKER_COMPOSE) \
3131
-f ./docker-compose.yml \
3232
up --wait \
33-
&& $(GO) run ./cmd/addevents |& bunyan
33+
&& $(GO) run -tags test ./cmd/addevents $(ARGS) |& bunyan
3434

3535
.PHONY: stop
3636
stop:

cmd/addevents/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `addevents` - Add fictives events to ClickHouse
22

3-
This directory contains a small CLI utils to add fictive data to ClickHouse.
3+
This directory contains a small CLI utils to add fake data to ClickHouse.
44

55
It serve to test ClickHouse schema changes manually and ensure our schema is
66
robust over time (e.g. when there is millions of events over past months).

cmd/addevents/app.go

Lines changed: 0 additions & 140 deletions
This file was deleted.

cmd/addevents/config.go

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,28 @@
11
package main
22

33
import (
4-
"math/rand"
5-
"strings"
6-
"time"
4+
"runtime"
75

86
"github.com/negrel/configue"
97
)
108

119
type Config struct {
12-
TotalEvents uint64 `json:"total_events"`
13-
BatchSize uint64 `json:"batch_size"`
14-
Domains []string `json:"domains"`
15-
FromDate time.Time `json:"from_date"`
16-
CustomEventsRate float64 `json:"custom_events_rate"`
17-
BounceRate float64 `json:"bounce_rate"`
18-
ExitRate float64 `json:"exit_rate"`
19-
MobileRate float64 `json:"mobile_rate"`
20-
VisitorIdsRange uint64 `json:"visitor_ids_range"`
21-
DirectTrafficRate float64 `json:"direct_traffic_rate"`
10+
BounceRate float64 `json:"bounce_rate"`
11+
CustomEventsRate float64 `json:"custom_events_rate"`
12+
DirectTrafficRate float64 `json:"direct_traffic_rate"`
13+
MobileRate float64 `json:"mobile_rate"`
14+
TotalSessions uint64 `json:"total_sessions"`
15+
PageViewsPerSession float64 `json:"view_per_session"`
16+
Workers uint64 `json:"workers"`
2217
}
2318

24-
// RegisterOptions returns a Config parsed from command line.
19+
// RegisterOptions registers options in provided Figue.
2520
func (c *Config) RegisterOptions(f *configue.Figue) {
26-
domains := "localhost,mywebsite.localhost,foo.mywebsite.localhost"
27-
var extraDomains int
28-
var extraPaths int
29-
30-
f.Uint64Var(&c.BatchSize, "batch.size", 40_000, "size of a batch")
31-
f.Uint64Var(&c.TotalEvents, "total.events", 4_000_000, "number of events to generate")
32-
f.StringVar(&domains, "domains", domains, "comma separated extra list of domains with events")
33-
f.IntVar(&extraDomains, "extra.domains", 10, "number of random domains generated added to the domains list")
34-
f.IntVar(&extraPaths, "extra.paths", 10, "number of random paths generated added to the paths list")
35-
f.Float64Var(&c.CustomEventsRate, "custom.events-rate", 0.3, "custom events rate per viewed page")
3621
f.Float64Var(&c.BounceRate, "bounce.rate", 0.56, "bounce rate")
37-
f.Float64Var(&c.ExitRate, "exit.rate", 0.3, "exit rate when no bounce")
38-
f.Float64Var(&c.MobileRate, "mobile.rate", 0.3, "mobile client rate")
39-
f.Uint64Var(&c.VisitorIdsRange, "visitor.ids", 40_000, "range of visitor ids")
22+
f.Float64Var(&c.CustomEventsRate, "custom.events-rate", 0.3, "custom events rate per viewed page")
4023
f.Float64Var(&c.DirectTrafficRate, "direct.rate", 0.5, "direct traffic rate against external traffic")
41-
42-
c.FromDate = time.Now().AddDate(0, -6, 0)
43-
44-
// Generate extra domains.
45-
for i := 0; i < extraDomains; i++ {
46-
c.Domains = append(c.Domains, randomString(alpha, 1)+randomString(alphaNum, rand.Intn(8))+randomItem([]string{".com", ".fr", ".eu", ".io", ".sh"}))
47-
}
48-
49-
// Generate extra paths
50-
for range 1000 {
51-
part := 1 + rand.Intn(8)
52-
var path []string
53-
for range part {
54-
path = append(path, "/"+randomString(alphaNum, 1+rand.Intn(8)))
55-
}
56-
57-
pathnamesList = append(pathnamesList, strings.Join(path, ""))
58-
}
59-
}
60-
61-
func (c Config) BatchCount() uint64 {
62-
return c.TotalEvents / c.BatchSize
24+
f.Float64Var(&c.MobileRate, "mobile.rate", 0.3, "mobile client rate")
25+
f.Uint64Var(&c.TotalSessions, "total.sessions", 4_000_000, "number of sessions")
26+
f.Float64Var(&c.PageViewsPerSession, "views.per.session", 3.5, "average number of page view per session")
27+
f.Uint64Var(&c.Workers, "workers", min(1, uint64(runtime.NumCPU()/2)), "number of worker")
6328
}

cmd/addevents/custom_event.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/addevents/embed.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

cmd/addevents/logger.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)