Skip to content

Commit

Permalink
Use new instance of logrus logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybeard committed Dec 12, 2024
1 parent 72e79b5 commit 12fcc9f
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 134 deletions.
4 changes: 2 additions & 2 deletions airflow/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/pkg/fileutil"
"github.com/astronomer/astro-cli/pkg/logger"
"github.com/astronomer/astro-cli/pkg/util"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/client"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

type ContainerHandler interface {
Expand Down Expand Up @@ -144,7 +144,7 @@ func generateConfig(projectName, airflowHome, envFile, buildImage, settingsFile

settingsFileExist, err := util.Exists("./" + settingsFile)
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}

cfg := ComposeConfig{
Expand Down
20 changes: 10 additions & 10 deletions airflow/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/astronomer/astro-cli/airflow/runtimes"
"github.com/astronomer/astro-cli/pkg/logger"

semver "github.com/Masterminds/semver/v3"
airflowTypes "github.com/astronomer/astro-cli/airflow/types"
Expand All @@ -38,7 +39,6 @@ import (
"github.com/docker/docker/api/types/versions"
"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -169,12 +169,12 @@ func DockerComposeInit(airflowHome, envFile, dockerfile, imageName string) (*Doc

dockerCli, err := command.NewDockerCli()
if err != nil {
logrus.Fatalf("error creating compose client %s", err)
logger.Logger.Fatalf("error creating compose client %s", err)
}

err = dockerCli.Initialize(flags.NewClientOptions())
if err != nil {
logrus.Fatalf("error init compose client %s", err)
logger.Logger.Fatalf("error init compose client %s", err)
}

composeService := compose.NewComposeService(dockerCli.Client(), &configfile.ConfigFile{})
Expand Down Expand Up @@ -348,7 +348,7 @@ func (d *DockerCompose) Stop(waitForExit bool) error {
for {
select {
case <-timeout:
logrus.Debug("timed out waiting for postgres container to be in exited state")
logger.Logger.Debug("timed out waiting for postgres container to be in exited state")
return nil
case <-ticker.C:
psInfo, _ := d.composeService.Ps(context.Background(), d.projectName, api.PsOptions{
Expand All @@ -359,10 +359,10 @@ func (d *DockerCompose) Stop(waitForExit bool) error {
// so docker compose will ensure that postgres container going in shutting down phase only after all other containers have exited
if strings.Contains(psInfo[i].Name, PostgresDockerContainerName) {
if psInfo[i].State == dockerExitState {
logrus.Debug("postgres container reached exited state")
logger.Logger.Debug("postgres container reached exited state")
return nil
}
logrus.Debugf("postgres container is still in %s state, waiting for it to be in exited state", psInfo[i].State)
logger.Logger.Debugf("postgres container is still in %s state, waiting for it to be in exited state", psInfo[i].State)
}
}
}
Expand Down Expand Up @@ -764,7 +764,7 @@ func upgradeDockerfile(oldDockerfilePath, newDockerfilePath, newTag, newImage st
if strings.HasPrefix(strings.TrimSpace(line), "FROM quay.io/astronomer/ap-airflow:") {
isRuntime, err := isRuntimeVersion(newTag)
if err != nil {
logrus.Debug(err)
logger.Logger.Debug(err)
}
if isRuntime {
// Replace the tag on the matching line
Expand Down Expand Up @@ -997,17 +997,17 @@ func writeToCompareFile(title string, pkgList []string, writer *bufio.Writer) {
if len(pkgList) > 0 {
_, err := writer.WriteString(title)
if err != nil {
logrus.Debug(err)
logger.Logger.Debug(err)
}
for _, pkg := range pkgList {
_, err = writer.WriteString(pkg + "\n")
if err != nil {
logrus.Debug(err)
logger.Logger.Debug(err)
}
}
_, err = writer.WriteString("\n")
if err != nil {
logrus.Debug(err)
logger.Logger.Debug(err)
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions airflow/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (

"github.com/astronomer/astro-cli/airflow/runtimes"

"github.com/astronomer/astro-cli/pkg/logger"
"github.com/astronomer/astro-cli/pkg/util"
cliCommand "github.com/docker/cli/cli/command"
cliConfig "github.com/docker/cli/cli/config"
cliTypes "github.com/docker/cli/cli/config/types"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
log "github.com/sirupsen/logrus"

airflowTypes "github.com/astronomer/astro-cli/airflow/types"
"github.com/astronomer/astro-cli/config"
Expand Down Expand Up @@ -145,7 +145,7 @@ func (d *DockerImage) Pytest(pytestFile, airflowHome, envFile, testHomeDirectory
}
err = cmdExec(containerRuntime, nil, nil, "rm", "astro-pytest")
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
// Change to location of Dockerfile
err = os.Chdir(buildConfig.Path)
Expand Down Expand Up @@ -211,7 +211,7 @@ func (d *DockerImage) Pytest(pytestFile, airflowHome, envFile, testHomeDirectory
// start pytest container
err = cmdExec(containerRuntime, stdout, stderr, []string{"start", "astro-pytest", "-a"}...)
if err != nil {
log.Debugf("Error starting pytest container: %s", err.Error())
logger.Logger.Debugf("Error starting pytest container: %s", err.Error())
}

// get exit code
Expand All @@ -223,27 +223,27 @@ func (d *DockerImage) Pytest(pytestFile, airflowHome, envFile, testHomeDirectory
var outb bytes.Buffer
docErr = cmdExec(containerRuntime, &outb, stderr, args...)
if docErr != nil {
log.Debug(docErr)
logger.Logger.Debug(docErr)
}

if htmlReport {
// Copy the dag-test-report.html file from the container to the destination folder
docErr = cmdExec(containerRuntime, nil, stderr, "cp", "astro-pytest:/usr/local/airflow/dag-test-report.html", "./"+testHomeDirectory)
if docErr != nil {
log.Debugf("Error copying dag-test-report.html file from the pytest container: %s", docErr.Error())
logger.Logger.Debugf("Error copying dag-test-report.html file from the pytest container: %s", docErr.Error())
}
}

// Persist the include folder from the Docker container to local include folder
docErr = cmdExec(containerRuntime, nil, stderr, "cp", "astro-pytest:/usr/local/airflow/include/", ".")
if docErr != nil {
log.Debugf("Error copying include folder from the pytest container: %s", docErr.Error())
logger.Logger.Debugf("Error copying include folder from the pytest container: %s", docErr.Error())
}

// delete container
docErr = cmdExec(containerRuntime, nil, stderr, "rm", "astro-pytest")
if docErr != nil {
log.Debugf("Error removing the astro-pytest container: %s", docErr.Error())
logger.Logger.Debugf("Error removing the astro-pytest container: %s", docErr.Error())
}

return outb.String(), err
Expand All @@ -257,7 +257,7 @@ func (d *DockerImage) ConflictTest(workingDirectory, testHomeDirectory string, b
// delete container
err = cmdExec(containerRuntime, nil, nil, "rm", "astro-temp-container")
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
// Change to location of Dockerfile
err = os.Chdir(buildConfig.Path)
Expand Down Expand Up @@ -375,7 +375,7 @@ func (d *DockerImage) Push(remoteImage, username, token string) error {

authConfig, err := configFile.GetAuthConfig(registry)
if err != nil {
log.Debugf("Error reading credentials: %v", err)
logger.Logger.Debugf("Error reading credentials: %v", err)
return fmt.Errorf("error reading credentials: %w", err)
}

Expand All @@ -384,7 +384,7 @@ func (d *DockerImage) Push(remoteImage, username, token string) error {
creds := configFile.GetCredentialsStore(registryDomain)
authConfig, err = creds.Get(registryDomain)
if err != nil {
log.Debugf("Error reading credentials for domain: %s from %s credentials store: %v", containerRuntime, registryDomain, err)
logger.Logger.Debugf("Error reading credentials for domain: %s from %s credentials store: %v", containerRuntime, registryDomain, err)
}
} else {
if username != "" {
Expand All @@ -394,7 +394,7 @@ func (d *DockerImage) Push(remoteImage, username, token string) error {
authConfig.ServerAddress = registry
}

log.Debugf("Exec Push %s creds %v \n", containerRuntime, authConfig)
logger.Logger.Debugf("Exec Push %s creds %v \n", containerRuntime, authConfig)

err = d.pushWithClient(&authConfig, remoteImage)
if err != nil {
Expand Down Expand Up @@ -441,19 +441,19 @@ func (d *DockerImage) pushWithClient(authConfig *cliTypes.AuthConfig, remoteImag

cli, err := getDockerClient()
if err != nil {
log.Debugf("Error setting up new Client ops %v", err)
logger.Logger.Debugf("Error setting up new Client ops %v", err)
return err
}
cli.NegotiateAPIVersion(ctx)
buf, err := json.Marshal(authConfig)
if err != nil {
log.Debugf("Error negotiating api version: %v", err)
logger.Logger.Debugf("Error negotiating api version: %v", err)
return err
}
encodedAuth := base64.URLEncoding.EncodeToString(buf)
responseBody, err := cli.ImagePush(ctx, remoteImage, types.ImagePushOptions{RegistryAuth: encodedAuth})
if err != nil {
log.Debugf("Error pushing image to docker: %v", err)
logger.Logger.Debugf("Error pushing image to docker: %v", err)
// if NewClientWithOpt does not work use bash to run docker commands
return err
}
Expand Down Expand Up @@ -607,7 +607,7 @@ func (d *DockerImage) Run(dagID, envFile, settingsFile, containerName, dagFile,
// delete container
err = cmdExec(containerRuntime, nil, nil, "rm", astroRunContainer)
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
var args []string
if containerName != "" {
Expand All @@ -620,7 +620,7 @@ func (d *DockerImage) Run(dagID, envFile, settingsFile, containerName, dagFile,
// check if settings file exists
settingsFileExist, err := util.Exists("./" + settingsFile)
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
// docker exec
if containerName == "" {
Expand All @@ -643,7 +643,7 @@ func (d *DockerImage) Run(dagID, envFile, settingsFile, containerName, dagFile,
// if env file exists append it to args
fileExist, err := util.Exists(config.WorkingPath + "/" + envFile)
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
if fileExist {
args = append(args, []string{"--env-file", envFile}...)
Expand Down Expand Up @@ -675,13 +675,13 @@ func (d *DockerImage) Run(dagID, envFile, settingsFile, containerName, dagFile,

fmt.Println("\nStarting a DAG run for " + dagID + "...")
fmt.Println("\nLoading DAGs...")
log.Debug("args passed to docker command:")
log.Debug(args)
logger.Logger.Debug("args passed to docker command:")
logger.Logger.Debug(args)

cmdErr := cmdExec(containerRuntime, stdout, stderr, args...)
// add back later fmt.Println("\nSee the output of this command for errors. To view task logs, use the '--task-logs' flag.")
if cmdErr != nil {
log.Debug(cmdErr)
logger.Logger.Debug(cmdErr)
fmt.Println("\nSee the output of this command for errors.")
fmt.Println("If you are having an issue with loading your settings file make sure both the 'variables' and 'connections' fields exist and that there are no yaml syntax errors.")
fmt.Println("If you are getting a missing `airflow_settings.yaml` or `astro-run-dag` error try restarting airflow with `astro dev restart`.")
Expand All @@ -690,7 +690,7 @@ func (d *DockerImage) Run(dagID, envFile, settingsFile, containerName, dagFile,
// delete container
err = cmdExec(containerRuntime, nil, nil, "rm", astroRunContainer)
if err != nil {
log.Debug(err)
logger.Logger.Debug(err)
}
}
return cmdErr
Expand Down
4 changes: 2 additions & 2 deletions airflow/docker_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"os"

"github.com/astronomer/astro-cli/pkg/logger"
cliConfig "github.com/docker/cli/cli/config"
cliTypes "github.com/docker/cli/cli/config/types"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/registry"
log "github.com/sirupsen/logrus"
)

type DockerRegistry struct {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (d *DockerRegistry) Login(username, token string) error {
authConfig.Password = auth.Password
}

log.Debugf("docker creds %v \n", authConfig)
logger.Logger.Debugf("docker creds %v \n", authConfig)
_, err := d.cli.RegistryLogin(ctx, authConfig)
if err != nil {
return fmt.Errorf("registry login error: %w", err)
Expand Down
14 changes: 7 additions & 7 deletions airflow/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
astrocore "github.com/astronomer/astro-cli/astro-client-core"
astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core"
astroplatformcore_mocks "github.com/astronomer/astro-cli/astro-client-platform-core/mocks"
"github.com/astronomer/astro-cli/pkg/logger"

"github.com/astronomer/astro-cli/config"
"github.com/sirupsen/logrus"

"github.com/astronomer/astro-cli/pkg/fileutil"
testUtil "github.com/astronomer/astro-cli/pkg/testing"
Expand Down Expand Up @@ -712,9 +712,9 @@ func (s *Suite) TestDockerComposeStop() {
mockDockerCompose.composeService = composeMock
mockDockerCompose.imageHandler = imageHandler

logrus.SetLevel(5) // debug level
logger.Logger.SetLevel(5) // debug level
var out bytes.Buffer
logrus.SetOutput(&out)
logger.Logger.SetOutput(&out)

err := mockDockerCompose.Stop(true)
s.NoError(err)
Expand All @@ -736,9 +736,9 @@ func (s *Suite) TestDockerComposeStop() {
mockDockerCompose.composeService = composeMock
mockDockerCompose.imageHandler = imageHandler

logrus.SetLevel(5) // debug level
logger.Logger.SetLevel(5) // debug level
var out bytes.Buffer
logrus.SetOutput(&out)
logger.Logger.SetOutput(&out)

err := mockDockerCompose.Stop(true)
s.NoError(err)
Expand All @@ -764,9 +764,9 @@ func (s *Suite) TestDockerComposeStop() {
mockDockerCompose.composeService = composeMock
mockDockerCompose.imageHandler = imageHandler

logrus.SetLevel(5) // debug level
logger.Logger.SetLevel(5) // debug level
var out bytes.Buffer
logrus.SetOutput(&out)
logger.Logger.SetOutput(&out)

err := mockDockerCompose.Stop(true)
s.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions cloud/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"net/url"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/astronomer/astro-cli/pkg/ansi"
"github.com/astronomer/astro-cli/pkg/domainutil"
"github.com/astronomer/astro-cli/pkg/httputil"
"github.com/astronomer/astro-cli/pkg/logger"
"github.com/astronomer/astro-cli/pkg/util"
)

Expand Down Expand Up @@ -155,7 +155,7 @@ func authorizeCallbackHandler() (string, error) {
})
go func() {
if err := s.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
logger.Logger.Fatal(err)
}
}()

Expand Down
Loading

0 comments on commit 12fcc9f

Please sign in to comment.