Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use structured logger #4046

Open
wants to merge 2 commits into
base: feature/single-region-accounts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions ecs-agent/tmds/handlers/v1/credentials_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"net/http"

"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
auditinterface "github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit/request"
handlersutils "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/utils"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils"
"github.com/cihub/seelog"
)

const (
Expand Down Expand Up @@ -104,7 +104,7 @@ func processCredentialsRequest(
) ([]byte, string, string, *handlersutils.ErrorMessage, error) {
if credentialsID == "" {
errText := errPrefix + "No Credential ID in the request"
seelog.Errorf("Error processing credential request: %s", errText)
logger.Error(fmt.Sprintf("Error processing credential request: %s", errText))
msg := &handlersutils.ErrorMessage{
Code: ErrNoIDInRequest,
Message: errText,
Expand All @@ -116,23 +116,25 @@ func processCredentialsRequest(
credentials, ok := credentialsManager.GetTaskCredentials(credentialsID)
if !ok {
errText := errPrefix + "Credentials not found"
seelog.Errorf("Error processing credential request: %s", errText)
logger.Error(fmt.Sprintf("Error processing credential request: %s", errText))
msg := &handlersutils.ErrorMessage{
Code: ErrInvalidIDInRequest,
Message: errText,
HTTPErrorCode: http.StatusBadRequest,
}
return nil, "", "", msg, errors.New(errText)
}

seelog.Infof("Processing credential request, credentialType=%s taskARN=%s credentialScope=%s",
credentials.IAMRoleCredentials.RoleType, credentials.ARN, credentials.IAMRoleCredentials.CredentialScope)
logger.Info("Processing credential request", logger.Fields{
"credentialType": credentials.IAMRoleCredentials.RoleType,
"taskARN": credentials.ARN,
"credentialScope": credentials.IAMRoleCredentials.CredentialScope,
})

if utils.ZeroOrNil(credentials.ARN) && utils.ZeroOrNil(credentials.IAMRoleCredentials) {
// This can happen when the agent is restarted and is reconciling its state.
errText := errPrefix + "Credentials uninitialized for ID"
seelog.Errorf("Error processing credential request credentialType=%s taskARN=%s credentialScope=%s: %s",
credentials.IAMRoleCredentials.RoleType, credentials.ARN, credentials.IAMRoleCredentials.CredentialScope, errText)
logger.Error(fmt.Sprintf("Error processing credential request credentialType=%s taskARN=%s credentialScope=%s: %s",
credentials.IAMRoleCredentials.RoleType, credentials.ARN, credentials.IAMRoleCredentials.CredentialScope, errText))
msg := &handlersutils.ErrorMessage{
Code: ErrCredentialsUninitialized,
Message: errText,
Expand All @@ -144,8 +146,8 @@ func processCredentialsRequest(
credentialsJSON, err := json.Marshal(credentials.IAMRoleCredentials)
if err != nil {
errText := errPrefix + "Error marshaling credentials"
seelog.Errorf("Error processing credential request credentialType=%s taskARN=%s credentialScope=%s: %s",
credentials.IAMRoleCredentials.RoleType, credentials.ARN, credentials.IAMRoleCredentials.CredentialScope, errText)
logger.Error(fmt.Sprintf("Error processing credential request credentialType=%s taskARN=%s credentialScope=%s: %s",
credentials.IAMRoleCredentials.RoleType, credentials.ARN, credentials.IAMRoleCredentials.CredentialScope, errText))
msg := &handlersutils.ErrorMessage{
Code: ErrInternalServer,
Message: "Internal server error",
Expand Down