Skip to content

OpenSearch cloudwatch logging - #548

Merged
jmarcos135 merged 28 commits into
mainfrom
es-cw-logging
Aug 10, 2026
Merged

OpenSearch cloudwatch logging#548
jmarcos135 merged 28 commits into
mainfrom
es-cw-logging

Conversation

@jmarcos135

@jmarcos135 jmarcos135 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • Adds self-service enablement of Audit, Error, SearchSlow, and IndexSlow logs publishing to cloudwatch for OpenSearch domains.
    • The broker provisions and manages cloudwatch log groups and then enables opensearch domains to publish logs to these groups.
    • Enabling Audit will enable FGAC on the domain in order to actually generate these logs. This is done as a convenience for customers. Since this is a permanent operation, it will be noted in the user docs.
    • SearchSlow and IndexSlow will need additional configuration of slow thresholds to generate anything meaningful, but this is a user responsibility. This is done with a PUT request to their domain using their app/domain credentials. This will be explained in the docs.

Things to check

  • For any logging statements, is there any chance that they could be logging sensitive data?
  • Are log statements using a logging library with a logging level set? Setting a logging level means that log statements "below" that level will not be written to the output. For example, if the logging level is set to INFO and debugging statements are written with log.debug or similar, then they won't be written to the otput, which can prevent unintentional leaks of sensitive data.

Security considerations

[Note the any security considerations here, or make note of why there are none]

@jmarcos135
jmarcos135 requested a review from a team as a code owner July 22, 2026 15:09
Comment thread ci/pipeline.yml
Comment thread ci/run-smoke-test-es-logging.sh Outdated
Comment thread services/elasticsearch/logs.go
Comment thread services/elasticsearch/logs.go Outdated
Comment on lines +108 to +111
if !errors.As(err, &alreadyExists) {
logger.Error("ensureLogGroups: CreateLogGroup err", "err", err, "logGroup", name)
return err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !errors.As(err, &alreadyExists) {
logger.Error("ensureLogGroups: CreateLogGroup err", "err", err, "logGroup", name)
return err
}
if !errors.As(err, &alreadyExists) {
logger.Error("ensureLogGroups: CreateLogGroup err", "err", err, "logGroup", name)
return err
}
return err

So we're catching the already exists error just to log it specifically? Or do we intend to ignore that error?

I also think we need to return the error if it's not already exists, so we don't trap those errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of this block was to catch errors that are NOT alreadyExists and return those. I'm treating alreadyExists errors as successful here. I can change the logic here to make it more clear to read.

Comment thread services/elasticsearch/logs_test.go Outdated
t.Run(name, func(t *testing.T) {
i := test.initial
i.applyLogOptions(test.options)
if i.AuditLogsEnabled != test.expectedAudit {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would it be easier to have an expectedInstance for each test case and compare against that instead of comparing each property individually?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this test file to match the pattern used in other unit tests

jmarcos135 and others added 3 commits August 3, 2026 10:16
Co-authored-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: James Marcos <marcosjames135@gmail.com>
Comment on lines +316 to +322
gotCreated := append([]string{}, client.createdLogGroups...)
wantCreated := append([]string{}, test.expectedCreated...)
sort.Strings(gotCreated)
sort.Strings(wantCreated)
if diff := deep.Equal(gotCreated, wantCreated); diff != nil {
t.Errorf("createdLogGroups: %v", diff)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gotCreated := append([]string{}, client.createdLogGroups...)
wantCreated := append([]string{}, test.expectedCreated...)
sort.Strings(gotCreated)
sort.Strings(wantCreated)
if diff := deep.Equal(gotCreated, wantCreated); diff != nil {
t.Errorf("createdLogGroups: %v", diff)
}
sort.Strings(client.createdLogGroup)
sort.Strings(test.expectedCreated)
if diff := deep.Equal(client.createdLogGroup, test.expectedCreated); diff != nil {
t.Errorf("createdLogGroups: %v", diff)
}

It's not important, but is there a reason this form wouldn't work?

markdboyd
markdboyd previously approved these changes Aug 4, 2026

@markdboyd markdboyd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @jmarcos135

@jmarcos135
jmarcos135 added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit e9f38c7 Aug 10, 2026
3 checks passed
@jmarcos135
jmarcos135 deleted the es-cw-logging branch August 10, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants