Skip to content

Commit f18f459

Browse files
author
Manish Ranjan Mahanta
committed
More Debug Logs
1 parent 3ebe430 commit f18f459

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

internal/gcs-sidecar/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ func (b *Bridge) modifyServiceSettings(req *request) (err error) {
527527

528528
// Update the allowed log sources in the settings. This will be forwarded to inbox GCS which expects the log sources in a JSON string format with GUIDs for providers included.
529529
allowedLogSources = etw.UpdateLogSources(req.ctx, allowedLogSources, false, true)
530+
log.G(req.ctx).Tracef("Allowed log sources after appending GUIDs: %v", allowedLogSources)
530531
settings.Settings = allowedLogSources
531532
}
532533
default:

internal/vm/vmutils/etw/provider_map.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,26 @@ func UpdateLogSources(ctx context.Context, base64EncodedJSONLogConfig string, us
257257
// Merge providers
258258
providerMap := make(map[string]EtwProvider)
259259
for _, provider := range defSrc.Providers {
260-
providerMap[provider.ProviderName] = provider
260+
key := provider.ProviderName
261+
if provider.ProviderGUID != "" {
262+
if key != "" {
263+
key = provider.ProviderName + "|" + provider.ProviderGUID
264+
} else {
265+
key = provider.ProviderGUID
266+
}
267+
}
268+
providerMap[key] = provider
261269
}
262270
for _, provider := range userSrc.Providers {
263-
providerMap[provider.ProviderName] = provider
271+
key := provider.ProviderName
272+
if provider.ProviderGUID != "" {
273+
if key != "" {
274+
key = provider.ProviderName + "|" + provider.ProviderGUID
275+
} else {
276+
key = provider.ProviderGUID
277+
}
278+
}
279+
providerMap[key] = provider
264280
}
265281
etwProviders := make([]EtwProvider, 0, len(providerMap))
266282
for _, provider := range providerMap {
@@ -288,11 +304,13 @@ func UpdateLogSources(ctx context.Context, base64EncodedJSONLogConfig string, us
288304
guid, err := NormalizeGUID(provider.ProviderGUID)
289305
if err != nil {
290306
log.G(ctx).Warningf("Skipping invalid GUID %q for provider %q: %v", provider.ProviderGUID, provider.ProviderName, err)
307+
// This will override the invalid GUID with an empty string, which is fine because we will still include the provider based on the name if it is valid.
291308
}
292309
resultLogCfg.LogConfig.Sources[i].Providers[j].ProviderGUID = guid
293310
}
294311
if provider.ProviderName != "" && provider.ProviderGUID == "" {
295312
resultLogCfg.LogConfig.Sources[i].Providers[j].ProviderGUID = GetProviderGUIDFromName(ctx, provider.ProviderName)
313+
log.G(ctx).Tracef("Mapped provider name %q to GUID %q", provider.ProviderName, resultLogCfg.LogConfig.Sources[i].Providers[j].ProviderGUID)
296314
}
297315
}
298316
}
@@ -310,6 +328,7 @@ func UpdateLogSources(ctx context.Context, base64EncodedJSONLogConfig string, us
310328
continue
311329
}
312330
if strings.EqualFold(guid, GetProviderGUIDFromName(ctx, provider.ProviderName)) {
331+
log.G(ctx).Tracef("Removing GUID %q for provider %q as it matches the GUID from the name in the ETW map", guid, provider.ProviderName)
313332
resultLogCfg.LogConfig.Sources[i].Providers[j].ProviderGUID = ""
314333
} else {
315334
resultLogCfg.LogConfig.Sources[i].Providers[j].ProviderGUID = guid
@@ -327,6 +346,8 @@ func UpdateLogSources(ctx context.Context, base64EncodedJSONLogConfig string, us
327346
return base64EncodedJSONLogConfig
328347
}
329348

349+
log.G(ctx).Tracef("Merged log config before encoding: %s", string(jsonBytes))
350+
330351
encodedCfg := base64.StdEncoding.EncodeToString(jsonBytes)
331352
return encodedCfg
332353

0 commit comments

Comments
 (0)