Skip to content

Commit

Permalink
cmd: log built-in-config.yaml and merged-config.yaml
Browse files Browse the repository at this point in the history
This change logs the config files on both windows and linux. It does so
by logging to STDOUT on linux and to the event log on windows.

TODO:
- Add screenshots of the log entries on pantheon
- Add tip to docs about the logs
  • Loading branch information
ridwanmsharif committed Sep 27, 2021
1 parent 262d192 commit 34a6cb8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cmd/google_cloud_ops_agent_engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -43,5 +44,27 @@ func run() error {
if err := confgenerator.MergeConfFiles(*input, confDebugFolder, "linux"); err != nil {
return err
}
if err := logConfigFiles(filepath.Join(confDebugFolder, "built-in-config.yaml"), filepath.Join(confDebugFolder, "merged-config.yaml")); err != nil {
return err
}
return confgenerator.GenerateFiles(filepath.Join(confDebugFolder, "merged-config.yaml"), *service, *logsDir, *stateDir, *outDir)
}

// logConfigFiles logs the built-in and merged config files to STDOUT. These are then written by journald to var/log/syslog and so to
// Cloud Logging once the ops-agent is running.
func logConfigFiles(builtInConfigFile, mergedConfigFile string) error {
builtInConfig, err := ioutil.ReadFile(builtInConfigFile)
if err != nil {
return err
}

mergedConfig, err := ioutil.ReadFile(mergedConfigFile)
if err != nil {
return err
}

log.Printf("Built-in config: %s", builtInConfig)
log.Printf("Merged config: %s", mergedConfig)

return nil
}
10 changes: 8 additions & 2 deletions cmd/ops_agent_windows/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ func (s *service) generateConfigs() error {
if err := confgenerator.MergeConfFiles(s.userConf, confDebugFolder, "windows"); err != nil {
return err
}
data, err := ioutil.ReadFile(filepath.Join(confDebugFolder, "merged-config.yaml"))
builtInConfig, err := ioutil.ReadFile(filepath.Join(confDebugFolder, "built-in-config.yaml"))
if err != nil {
return err
}
uc, err := confgenerator.ParseUnifiedConfigAndValidate(data, "windows")
mergedConfig, err := ioutil.ReadFile(filepath.Join(confDebugFolder, "merged-config.yaml"))
if err != nil {
return err
}
s.log.Info(1, fmt.Sprintf("Built-in config: %s", builtInConfig))
s.log.Info(1, fmt.Sprintf("Merged config: %s", mergedConfig))
uc, err := confgenerator.ParseUnifiedConfigAndValidate(mergedConfig, "windows")
if err != nil {
return err
}
Expand Down

0 comments on commit 34a6cb8

Please sign in to comment.