Skip to content

Commit

Permalink
chore: update logs
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Jun 21, 2024
1 parent a4d97fd commit 2645c4b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
27 changes: 12 additions & 15 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
executableName string = "rr"
// cleanup pattern
cleanupPattern string = "roadrunner-server*"
ldflags string = "-X github.com/roadrunner-server/roadrunner/v2024/internal/meta.version=%s -X github.com/roadrunner-server/roadrunner/v2024/internal/meta.buildTime=%s"
)

var replaceRegexp = regexp.MustCompile("(\t| )(.+) => (.+)")
Expand Down Expand Up @@ -98,7 +99,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
return fmt.Errorf("unknown module version: %s", t.ModuleVersion)
}

b.log.Debug("[RESULTING TEMPLATE]", slog.String("template", buf.String()))
b.log.Debug("template", slog.String("template", buf.String()))

f, err := os.Open(b.rrTempPath)
if err != nil {
Expand All @@ -112,7 +113,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
}

for i := 0; i < len(files); i++ {
b.log.Info("[CLEANING UP]", slog.String("file/folder", files[i]))
b.log.Info("cleaning temporary folders", slog.String("file/folder", files[i]))
_ = os.RemoveAll(files[i])
}
}()
Expand Down Expand Up @@ -161,7 +162,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
return fmt.Errorf("unknown module version: %s", t.ModuleVersion)
}

b.log.Debug("[RESULTING TEMPLATE]", slog.String("template", buf.String()))
b.log.Debug("template", slog.String("template", buf.String()))

_, err = goModFile.Write(buf.Bytes())
if err != nil {
Expand All @@ -170,7 +171,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo

buf.Reset()

b.log.Info("[SWITCHING WORKING DIR]", slog.String("wd", b.rrTempPath))
b.log.Info("switching working directory", slog.String("wd", b.rrTempPath))
err = syscall.Chdir(b.rrTempPath)
if err != nil {
return err
Expand All @@ -186,7 +187,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
return err
}

b.log.Info("[CHECKING OUTPUT DIR]", slog.String("dir", b.out))
b.log.Info("creating output directory", slog.String("dir", b.out))
err = os.MkdirAll(b.out, os.ModeDir)
if err != nil {
return err
Expand All @@ -197,7 +198,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
return err
}

b.log.Info("[MOVING EXECUTABLE]", slog.String("file", filepath.Join(b.rrTempPath, executableName)), slog.String("to", filepath.Join(b.out, executableName)))
b.log.Info("moving binary", slog.String("file", filepath.Join(b.rrTempPath, executableName)), slog.String("to", filepath.Join(b.out, executableName)))
err = moveFile(filepath.Join(b.rrTempPath, executableName), filepath.Join(b.out, executableName))
if err != nil {
return err
Expand Down Expand Up @@ -256,11 +257,7 @@ func (b *Builder) goBuildCmd(out string) error {

// LDFLAGS for version and build time, always appended
buildCmdArgs = append(buildCmdArgs, "-ldflags")
buildCmdArgs = append(buildCmdArgs, fmt.Sprintf(
"-X github.com/roadrunner-server/roadrunner/v2024/internal/meta.version=%s -X github.com/roadrunner-server/roadrunner/v2024/internal/meta.buildTime=%s",
b.rrVersion,
time.Now().UTC().Format(time.RFC3339)),
)
buildCmdArgs = append(buildCmdArgs, fmt.Sprintf(ldflags, b.rrVersion, time.Now().UTC().Format(time.RFC3339)))

// output
buildCmdArgs = append(buildCmdArgs, "-o")
Expand All @@ -271,7 +268,7 @@ func (b *Builder) goBuildCmd(out string) error {

cmd = exec.Command("go", buildCmdArgs...)

b.log.Info("[EXECUTING CMD]", slog.String("cmd", cmd.String()))
b.log.Info("building RoadRunner", slog.String("cmd", cmd.String()))
cmd.Stderr = b
cmd.Stdout = b
err := cmd.Start()
Expand All @@ -286,7 +283,7 @@ func (b *Builder) goBuildCmd(out string) error {
}

func (b *Builder) goModDowloadCmd() error {
b.log.Info("[EXECUTING CMD]", slog.String("cmd", "go mod download"))
b.log.Info("downloading dependencies", slog.String("cmd", "go mod download"))
cmd := exec.Command("go", "mod", "download")
cmd.Stderr = b
err := cmd.Start()
Expand All @@ -301,7 +298,7 @@ func (b *Builder) goModDowloadCmd() error {
}

func (b *Builder) goModTidyCmd() error {
b.log.Info("[EXECUTING CMD]", slog.String("cmd", "go mod tidy"))
b.log.Info("updating dependencies", slog.String("cmd", "go mod tidy"))
cmd := exec.Command("go", "mod", "tidy")
cmd.Stderr = b
err := cmd.Start()
Expand All @@ -316,7 +313,7 @@ func (b *Builder) goModTidyCmd() error {
}

func (b *Builder) getDepsReplace(repl string) []*templates.Entry {
b.log.Info("[REPLACING DEPENDENCIES]", slog.String("dependency", repl))
b.log.Info("found replace, processing", slog.String("dependency", repl))
modFile, err := os.ReadFile(path.Join(repl, goModStr))
if err != nil {
return nil
Expand Down
10 changes: 5 additions & 5 deletions github/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (p *processor) run() {
go func() {
for v := range p.queueCh {
modInfo := new(velox.ModulesInfo)
p.log.Debug("[FETCHING PLUGIN DATA]",
p.log.Debug("fetching plugin data",
slog.String("repository", v.pluginCfg.Repo),
slog.String("owner", v.pluginCfg.Owner),
slog.String("folder", v.pluginCfg.Folder),
Expand Down Expand Up @@ -93,7 +93,7 @@ func (p *processor) run() {
line := scanner.Text()
switch { //nolint:gocritic
case strings.HasPrefix(line, modLine):
p.log.Debug("[READING MODULE INFO]", slog.String("plugin", v.name), slog.String("module", line))
p.log.Debug("reading module info", slog.String("plugin", v.name), slog.String("module", line))

// module github.com/roadrunner-server/logger/v2, we split and get the second part
retMod := strings.Split(line, " ")
Expand All @@ -115,10 +115,10 @@ func (p *processor) run() {

err = resp.Body.Close()
if err != nil {
p.log.Warn("[FAILED TO CLOSE RESPONSE BODY]", slog.Any("error", err))
p.log.Warn("failed to close response body, continuing", slog.Any("error", err))
}

p.log.Debug("[REQUESTING COMMIT SHA-1]", slog.String("plugin", v.name), slog.String("ref", v.pluginCfg.Ref))
p.log.Debug("requesting commit", slog.String("plugin", v.name), slog.String("ref", v.pluginCfg.Ref))
commits, rsp, err := p.client.Repositories.ListCommits(context.Background(), v.pluginCfg.Owner, v.pluginCfg.Repo, &github.CommitsListOptions{
SHA: v.pluginCfg.Ref,
Until: time.Now(),
Expand Down Expand Up @@ -155,7 +155,7 @@ func (p *processor) run() {

if v.pluginCfg.Replace != "" {
modInfo.Replace = v.pluginCfg.Replace
p.log.Debug("[REPLACE REQUESTED]", slog.String("plugin", v.name), slog.String("path", v.pluginCfg.Replace))
p.log.Debug("found replace, applying", slog.String("plugin", v.name), slog.String("path", v.pluginCfg.Replace))
}

p.mu.Lock()
Expand Down
14 changes: 7 additions & 7 deletions github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewGHRepoInfo(cfg *velox.Config, log *slog.Logger) *GHRepo {

// DownloadTemplate downloads template repository ->
func (r *GHRepo) DownloadTemplate(tmp, version string) (string, error) { //nolint:gocyclo
r.log.Info("[GET ARCHIVE LINK]", slog.String("owner", rrOwner), slog.String("repository", rrRepo), slog.String("encoding", "zip"), slog.String("ref", version))
r.log.Info("obtaining link", slog.String("owner", rrOwner), slog.String("repository", rrRepo), slog.String("encoding", "zip"), slog.String("ref", version))
url, resp, err := r.client.Repositories.GetArchiveLink(context.Background(), rrOwner, rrRepo, github.Zipball, &github.RepositoryContentGetOptions{Ref: version}, 10)
if err != nil {
return "", err
Expand All @@ -63,14 +63,14 @@ func (r *GHRepo) DownloadTemplate(tmp, version string) (string, error) { //nolin
return "", fmt.Errorf("wrong response status, got: %d", resp.StatusCode)
}

r.log.Info("[REQUESTING REPO]", slog.String("url", url.String()))
r.log.Info("seding download request", slog.String("url", url.String()))
request, err := r.client.NewRequest(http.MethodGet, url.String(), nil)
if err != nil {
return "", err
}

buf := new(bytes.Buffer)
r.log.Info("[FETCHING CONTENT]", slog.String("url", url.String()))
r.log.Info("downloading repository", slog.String("url", url.String()))
do, err := r.client.Do(context.Background(), request, buf)
if err != nil {
return "", err
Expand All @@ -85,7 +85,7 @@ func (r *GHRepo) DownloadTemplate(tmp, version string) (string, error) { //nolin
name := path.Join(tmp, "roadrunner-server-"+version)
_ = os.RemoveAll(name)

r.log.Debug("[FLUSHING DATA ON THE DISK]", slog.String("path", name+zipExt))
r.log.Debug("saving repository in temporary folder", slog.String("path", name+zipExt))
f, err := os.Create(name + zipExt)
if err != nil {
return "", err
Expand All @@ -100,7 +100,7 @@ func (r *GHRepo) DownloadTemplate(tmp, version string) (string, error) { //nolin
return "", err
}

r.log.Debug("[SAVED]", slog.Int("bytes written", n))
r.log.Debug("repository saved", slog.Int("bytes written", n))

rc, err := zip.OpenReader(name + zipExt)
if err != nil {
Expand Down Expand Up @@ -142,14 +142,14 @@ func (r *GHRepo) DownloadTemplate(tmp, version string) (string, error) { //nolin

outDir := rc.File[0].Name
for _, zf := range rc.File {
r.log.Debug("[EXTRACTING]", slog.String("file", zf.Name), slog.String("path", dest))
r.log.Debug("extracting repository", slog.String("file", zf.Name), slog.String("path", dest))
err = extract(dest, zf)
if err != nil {
return "", err
}
}

r.log.Info("[REPOSITORY SUCCESSFULLY SAVED]", slog.String("path", filepath.Join(dest, outDir))) //nolint:gosec
r.log.Info("repository saved", slog.String("path", filepath.Join(dest, outDir))) //nolint:gosec
// first name is the output path
return filepath.Join(dest, outDir), nil //nolint:gosec
}
Expand Down
8 changes: 4 additions & 4 deletions gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {

for k, v := range r.config.GitLab.Plugins {
modInfo := new(velox.ModulesInfo)
r.log.Debug("[FETCHING PLUGIN DATA]", slog.String("repository", v.Repo), slog.String("owner", v.Owner), slog.String("folder", v.Folder), slog.String("plugin", k), slog.String("ref", v.Ref))
r.log.Debug("fetchin plugin data", slog.String("repository", v.Repo), slog.String("owner", v.Owner), slog.String("folder", v.Folder), slog.String("plugin", k), slog.String("ref", v.Ref))

if v.Ref == "" {
return nil, errors.New("ref can't be empty")
Expand All @@ -70,7 +70,7 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {
scanner.Scan()
ret := scanner.Text()

r.log.Debug("[READING MODULE INFO]", slog.String("plugin", k), slog.String("mod", ret))
r.log.Debug("reading module info", slog.String("plugin", k), slog.String("mod", ret))

// module github.com/roadrunner-server/logger/v2, we split and get the second part
retMod := strings.Split(ret, " ")
Expand All @@ -85,7 +85,7 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {

modInfo.ModuleName = strings.TrimRight(retMod[1], "\n")

r.log.Debug("[REQUESTING REPO BY REF]", slog.String("plugin", k), slog.String("ref", v.Ref))
r.log.Debug("downloading repository", slog.String("plugin", k), slog.String("ref", v.Ref))
commits, rsp, err := r.client.Commits.ListCommits(v.Repo, &gitlab.ListCommitsOptions{
ListOptions: gitlab.ListOptions{
Page: 1,
Expand Down Expand Up @@ -123,7 +123,7 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {
modInfo.PseudoVersion = velox.ParseModuleInfo(modInfo.ModuleName, *at, modInfo.Version)

if v.Replace != "" {
r.log.Debug("[REPLACE REQUESTED]", slog.String("plugin", k), slog.String("path", v.Replace))
r.log.Debug("found replace, applying", slog.String("plugin", k), slog.String("path", v.Replace))
}

modInfo.Replace = v.Replace
Expand Down
2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BuildLogger(level, mode string) *slog.Logger {
return slog.New(lg)
case development:
lg := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
AddSource: false,
Level: stringToSlogLevel(level),
})
return slog.New(lg)
Expand Down
2 changes: 1 addition & 1 deletion velox_rr_v2024.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ref = "v2024.1.5"

# debug option is used to build RR with debug symbols to profile it with pprof
[debug]
enabled = true
enabled = false

[github]
[github.token]
Expand Down

0 comments on commit 2645c4b

Please sign in to comment.