-
Notifications
You must be signed in to change notification settings - Fork 69
/
tracetest.go
118 lines (96 loc) 路 4.05 KB
/
tracetest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package installer
import (
"bytes"
_ "embed"
"html/template"
"fmt"
"strings"
cliUI "github.com/kubeshop/tracetest/cli/ui"
)
func configureDemoApp(conf configuration, ui cliUI.UI) configuration {
conf.set("demo.enable.pokeshop", !conf.Bool("installer.only_tracetest"))
conf.set("demo.enable.otel", false)
switch conf.String("installer") {
case "docker-compose":
conf.set("demo.endpoint.pokeshop.http", "http://demo-api:8081")
conf.set("demo.endpoint.pokeshop.grpc", "demo-api:8082")
conf.set("demo.endpoint.otel.frontend", "http://otel-frontend:8084")
conf.set("demo.endpoint.otel.product_catalog", "otel-productcatalogservice:3550")
conf.set("demo.endpoint.otel.cart", "otel-cartservice:7070")
conf.set("demo.endpoint.otel.checkout", "otel-checkoutservice:5050")
case "kubernetes":
conf.set("demo.endpoint.pokeshop.http", "http://demo-pokemon-api.demo")
conf.set("demo.endpoint.pokeshop.grpc", "demo-pokemon-api.demo:8082")
conf.set("demo.endpoint.otel.frontend", "http://otel-frontend.otel-demo:8084")
conf.set("demo.endpoint.otel.product_catalog", "otel-productcatalogservice.otel-demo:3550")
conf.set("demo.endpoint.otel.cart", "otel-cartservice.otel-demo:7070")
conf.set("demo.endpoint.otel.checkout", "otel-checkoutservice.otel-demo:5050")
}
return conf
}
func configureTracetest(conf configuration, ui cliUI.UI) configuration {
conf = configureBackend(conf, ui)
conf.set("tracetest.analytics", true)
return conf
}
func configureBackend(conf configuration, ui cliUI.UI) configuration {
installBackend := !conf.Bool("installer.only_tracetest")
conf.set("tracetest.backend.install", installBackend)
if installBackend {
// default values
switch conf.String("installer") {
case "docker-compose":
conf.set("tracetest.backend.type", "otlp")
conf.set("tracetest.backend.tls.insecure", true)
conf.set("tracetest.backend.endpoint.collector", "http://otel-collector:4317")
conf.set("tracetest.backend.endpoint", "tracetest:21321")
case "kubernetes":
conf.set("tracetest.backend.type", "otlp")
conf.set("tracetest.backend.tls.insecure", true)
conf.set("tracetest.backend.endpoint.collector", "http://otel-collector.tracetest:4317")
conf.set("tracetest.backend.endpoint", "tracetest:21321")
default:
conf.set("tracetest.backend.type", "")
}
return conf
}
conf.set("tracetest.backend.type", "")
return conf
}
//go:embed config.yaml.tpl
var configTemplate string
func getTracetestConfigFileContents(psql string, ui cliUI.UI, config configuration) []byte {
enabledDemos := []string{}
if config.Bool("demo.enable.pokeshop") {
enabledDemos = append(enabledDemos, "pokeshop")
}
if config.Bool("demo.enable.otel") {
enabledDemos = append(enabledDemos, "otel")
}
vals := map[string]string{
"installBackend": fmt.Sprintf("%t", config.Bool("tracetest.backend.install")),
"psql": psql,
"analyticsEnabled": fmt.Sprintf("%t", config.Bool("tracetest.analytics")),
"enabledDemos": strings.Join(enabledDemos, ", "),
"pokeshopHttp": config.String("demo.endpoint.pokeshop.http"),
"pokeshopGrpc": config.String("demo.endpoint.pokeshop.grpc"),
"otelFrontend": config.String("demo.endpoint.otel.frontend"),
"otelProductCatalog": config.String("demo.endpoint.otel.product_catalog"),
"otelCart": config.String("demo.endpoint.otel.cart"),
"otelCheckout": config.String("demo.endpoint.otel.checkout"),
"backendType": config.String("tracetest.backend.type"),
"backendEndpoint": config.String("tracetest.backend.endpoint.query"),
"backendInsecure": config.String("tracetest.backend.tls.insecure"),
"backendAddresses": config.String("tracetest.backend.addresses"),
"backendIndex": config.String("tracetest.backend.index"),
"backendToken": config.String("tracetest.backend.token"),
"backendRealm": config.String("tracetest.backend.realm"),
}
tpl, err := template.New("page").Parse(configTemplate)
if err != nil {
ui.Panic(fmt.Errorf("cannot parse config template: %w", err))
}
out := &bytes.Buffer{}
tpl.Execute(out, vals)
return out.Bytes()
}