Skip to content

Commit fbeb484

Browse files
committed
[config change] OpenTelemetry tracing is now a pointer
* and `omitempty` Signed-off-by: Alex Aizman <alex.aizman@gmail.com>
1 parent 2b0de20 commit fbeb484

File tree

3 files changed

+78
-47
lines changed

3 files changed

+78
-47
lines changed

ais/daemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func initDaemon(version, buildTime string) cos.Runner {
243243
cmn.Init(p.si.Name(), nil)
244244

245245
// init distributed tracing
246-
tracing.Init(&config.Tracing, p.si, nil, version)
246+
tracing.Init(config.Tracing, p.si, nil, version)
247247

248248
// check ulimits
249249
checkUlimits(apc.UlimitProxy, config.TestingEnv())
@@ -266,7 +266,7 @@ func initDaemon(version, buildTime string) cos.Runner {
266266
cmn.Init(t.si.Name(), fs.CleanPathErr)
267267

268268
// init distributed tracing
269-
tracing.Init(&config.Tracing, t.si, nil, version)
269+
tracing.Init(config.Tracing, t.si, nil, version)
270270

271271
cmn.InitObjProps2Hdr()
272272

cmn/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type (
109109
Proxy ProxyConf `json:"proxy" allow:"cluster"`
110110
Cksum CksumConf `json:"checksum" allow:"cluster"`
111111
Auth AuthConf `json:"auth" allow:"cluster"`
112-
Tracing TracingConf `json:"tracing"`
112+
Tracing *TracingConf `json:"tracing,omitempty"`
113113
TCB TCBConf `json:"tcb" allow:"cluster"`
114114
TCO TCOConf `json:"tco" allow:"cluster"`
115115
Arch ArchConf `json:"arch" allow:"cluster"`
@@ -646,8 +646,8 @@ type (
646646

647647
// AuthConfV4 [backwards compatibility]: v4.0 and prior
648648
AuthConfV4 struct {
649-
Enabled bool `json:"enabled"`
650649
Secret string `json:"secret"`
650+
Enabled bool `json:"enabled"`
651651
}
652652

653653
AuthConfV4ToSet struct {
@@ -656,9 +656,6 @@ type (
656656
}
657657

658658
AuthConf struct {
659-
// Enable external user authentication via JWT/OIDC tokens
660-
// (does not control internal cluster security - see ClusterConfig)
661-
Enabled bool `json:"enabled"`
662659
// Fields for validating JWT signature
663660
Signature *AuthSignatureConf `json:"signature,omitempty"`
664661
// JWT claims to validate
@@ -668,6 +665,10 @@ type (
668665

669666
// Cluster key config
670667
ClusterKey *ClusterKeyConf `json:"cluster_key,omitempty"`
668+
669+
// Enable external user authentication via JWT/OIDC tokens
670+
// (does not control internal cluster security - see ClusterConfig)
671+
Enabled bool `json:"enabled"`
671672
}
672673
AuthConfToSet struct {
673674
Enabled *bool `json:"enabled,omitempty"`
@@ -691,8 +692,8 @@ type (
691692
Aud *[]string `json:"aud,omitempty"`
692693
}
693694
OIDCConf struct {
694-
AllowedIssuers []string `json:"allowed_iss"`
695695
IssuerCA string `json:"issuer_ca_bundle,omitempty"`
696+
AllowedIssuers []string `json:"allowed_iss"`
696697
}
697698
OIDCConfToSet struct {
698699
AllowedIssuers *[]string `json:"allowed_iss,omitempty"`

tracing/tracing_on.go

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,78 @@ import (
2929
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
3030
)
3131

32-
var tp *trace.TracerProvider
32+
// Init() enables OpenTelemetry tracing for an AIS node.
33+
// Semantics and constraints:
34+
// - Build-time feature:
35+
// This function is only compiled when AIS is built with the `oteltracing`
36+
// build tag (see tracing_off.go for the no-op stub used otherwise).
37+
// Callers invoke Init() unconditionally.
38+
// - Config handling:
39+
// The config.Tracing field is a *cmn.TracingConf pointer. A nil conf
40+
// or a conf with Enabled == false is treated as "tracing disabled":
41+
// - we log an informational message and return without error.
42+
// This makes it safe to omit the `tracing` section from ais.conf entirely.
43+
// - Exporter endpoint:
44+
// When tracing is enabled, ExporterEndpoint MUST be non-empty. If it is
45+
// empty we log an error, trip a debug.Assert in debug builds, and return
46+
// without installing a tracer provider. The node continues to run with
47+
// tracing effectively disabled.
48+
// - Error handling (is intentionally tolerant):
49+
// Any failure to construct the exporter (newExporter) or resource will
50+
// trip debug assertions but will not crash non-debug builds. In those
51+
// cases, tp remains nil and no global tracer provider is installed.
52+
53+
var (
54+
tp *trace.TracerProvider
55+
)
56+
57+
func Init(conf *cmn.TracingConf, snode *meta.Snode, exp any /* trace.SpanExporter */, version string) {
58+
if conf == nil || !conf.Enabled {
59+
nlog.Infof("distributed tracing not enabled (%+v)", conf)
60+
return
61+
}
62+
if conf.ExporterEndpoint == "" {
63+
nlog.Errorln("exporter endpoint can't be empty")
64+
debug.Assert(false)
65+
return
66+
}
67+
var (
68+
exporter trace.SpanExporter
69+
err error
70+
ok bool
71+
)
72+
if exp == nil {
73+
// default trace.SpanExporter
74+
exporter, err = newExporter(conf)
75+
if err != nil {
76+
nlog.Errorln("failed to start exporter:", err)
77+
debug.AssertNoErr(err)
78+
return
79+
}
80+
} else {
81+
// unit test
82+
exporter, ok = exp.(trace.SpanExporter)
83+
debug.Assertf(ok, "invalid exporter type %T", exp)
84+
}
85+
tp = trace.NewTracerProvider(
86+
trace.WithSampler(trace.ParentBased(trace.TraceIDRatioBased(conf.SamplerProbability))),
87+
trace.WithBatcher(exporter),
88+
trace.WithResource(newResource(conf, snode, version)),
89+
)
90+
91+
otel.SetTextMapPropagator(
92+
propagation.NewCompositeTextMapPropagator(
93+
propagation.TraceContext{},
94+
propagation.Baggage{},
95+
),
96+
)
97+
otel.SetTracerProvider(tp)
98+
}
3399

34100
func loadAccessToken(tokenFilePath string) string {
35-
cos.AssertMsg(tokenFilePath != "", "token filepath cannot be empty")
101+
debug.Assert(tokenFilePath != "", "token filepath cannot be empty")
36102
data, err := os.ReadFile(tokenFilePath)
37-
cos.AssertNoErr(err)
103+
debug.AssertNoErr(err)
38104
return strings.TrimSpace(string(data))
39105
}
40106

@@ -86,42 +152,6 @@ func IsEnabled() bool {
86152
return tp != nil
87153
}
88154

89-
func Init(conf *cmn.TracingConf, snode *meta.Snode, exp any /* trace.SpanExporter */, version string) {
90-
if conf == nil || !conf.Enabled {
91-
nlog.Infof("distributed tracing not enabled (%+v)", conf)
92-
return
93-
}
94-
cos.AssertMsg(conf.ExporterEndpoint != "", "exporter endpoint can't be empty")
95-
96-
var (
97-
exporter trace.SpanExporter
98-
err error
99-
ok bool
100-
)
101-
if exp == nil {
102-
// default trace.SpanExporter
103-
exporter, err = newExporter(conf)
104-
cos.AssertNoErr(err)
105-
} else {
106-
// unit test
107-
exporter, ok = exp.(trace.SpanExporter)
108-
debug.Assertf(ok, "invalid exporter type %T", exp)
109-
}
110-
tp = trace.NewTracerProvider(
111-
trace.WithSampler(trace.ParentBased(trace.TraceIDRatioBased(conf.SamplerProbability))),
112-
trace.WithBatcher(exporter),
113-
trace.WithResource(newResource(conf, snode, version)),
114-
)
115-
116-
otel.SetTextMapPropagator(
117-
propagation.NewCompositeTextMapPropagator(
118-
propagation.TraceContext{},
119-
propagation.Baggage{},
120-
),
121-
)
122-
otel.SetTracerProvider(tp)
123-
}
124-
125155
// used in tests only
126156
func ForceFlush() { tp.ForceFlush(context.Background()) }
127157

0 commit comments

Comments
 (0)