Skip to content

External Audit Storage: Connection Tester#34278

Merged
nklaassen merged 1 commit into
masterfrom
logan/byob-test-connection
Nov 23, 2023
Merged

External Audit Storage: Connection Tester#34278
nklaassen merged 1 commit into
masterfrom
logan/byob-test-connection

Conversation

@logand22
Copy link
Copy Markdown
Contributor

@logand22 logand22 commented Nov 6, 2023

This PR adds a test connection methods for the currently configured draft external cloud audit resource.

Additionally adds an additional connection tester for the test for kind for externalcloudaudit kind. This will help facilitate the connection testing from teleport UI portion that @mcbattirola is working on.

Related:

Comment thread lib/auth/auth.go Outdated
@logand22 logand22 force-pushed the logan/byob-test-connection branch 2 times, most recently from 7e0dab3 to 16cceb7 Compare November 15, 2023 23:47
@logand22 logand22 marked this pull request as ready for review November 16, 2023 00:20
@logand22 logand22 requested a review from nklaassen November 16, 2023 00:20
@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@logand22 logand22 changed the title BYOB: Test Connection BYOB: Connection Tester Nov 16, 2023
@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

2 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

Comment thread lib/services/externalcloudaudit.go Outdated
Comment thread lib/integrations/externalcloudaudit/connection_test.go Outdated
Comment thread lib/services/local/externalcloudaudit_test.go Outdated
Comment thread lib/services/local/externalcloudaudit.go Outdated
Comment thread lib/integrations/externalcloudaudit/connection.go Outdated
@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

4 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions
Copy link
Copy Markdown
Contributor

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

Comment thread lib/client/conntest/externalcloudaudit.go Outdated
@logand22 logand22 added the no-changelog Indicates that a PR does not require a changelog entry label Nov 20, 2023
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
@klizhentas klizhentas changed the title BYOB: Connection Tester External Audit Storage: Connection Tester Nov 20, 2023
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment on lines 80 to 81
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.

It's a pretty uncommon pattern to pass around an error to be handled by another function. Can each of these helper functions make the appropriate call to test and handle the error instead of splitting the error handling out into its own function?

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.

So I copied this pattern from the kube conn test shown here:

tlsCfg, err := s.genKubeRestTLSClientConfig(ctx, mfaResponse, connectionDiagnosticID, req.ResourceName, currentUser.GetName())
diag, diagErr := s.handleUserGenCertsErr(ctx, req.ResourceName, connectionDiagnosticID, err)
if err != nil || diagErr != nil {
return diag, diagErr
}
. However, I've reworked it based on your feedback in this commit: b4e4510.

Let me know what you think.

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.

Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
Comment thread lib/client/conntest/externalcloudaudit.go Outdated
@rosstimothy rosstimothy self-requested a review November 21, 2023 20:35
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.

Do we need to return both errors? Can we use trace.NewAggregate to combine them into a single error?

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.

I'm thinking it through. We return early on either a diagnostic error or a test connection error. We wrap the test connection error or success into the diagnostic and return the diagnostic error, if any, that occurs when we perform the test connection.

If we aggregate the error then we could simplify the conditional check but it would cause the return error to be non-nil when the test connection was non-nil. We currently return just the diagErr because the test connection error is wrapped into the diagnostics.

I don't know if trace.NewAggregate would allow us to return a nil error regardless of test connection, but then return the diagError if it occurs.

If we are looking for simpler logic, I could create a struct like this:

type ConnectionError struct{
    DiagErr error
    Err error
}

func (c ConnectionError) Error() string {
    return trace.NewAggregate(c.DiagErr, c.Err)
}

and then use it like:

func (s ExternalAuditStorageConnectionTester) handleBucketsTest(ctx context.Context, connectionDiagnosticID string) (types.ConnectionDiagnostic, error) {
...
diag, err := s.handleBucketsTest(ctx, connectionDiagnosticID)
if err != nil {
    return diag, err.(ConnectionError).DiagErr
}

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.

Or just return the ConnectionError directly instead of return the error.

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.

Hey @rosstimothy it's a bit confusing but I think the original is the cleanest way to handle this, we can just rename the test error

	testErr = client.TestDraftExternalCloudAuditBuckets(ctx)
	diag, diagErr := s.handleErrFromBucketsTest(ctx, connectionDiagnosticID, testErr)
	if testErr != nil || diagErr != nil {
		return diag, diagErr
	}

testErr is not really an error for the sake of this function, it's just the subtest result, so I don't really consider it passing of error handling to another function. handleErrFromBucketsTest tries to append a diagnostic trace about whether the subtest passed or failed, but may itself fail to add the trace. We want to return early if either the subtest failed, or we failed to add the trace.

We could even name it testResult and handleResultFromBucketsTest

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.

I suppose if that's the established pattern then I'm okay following it here. Though it is a curious pattern.

@rosstimothy rosstimothy self-requested a review November 22, 2023 18:51
This PR adds test connection methods for the current draft External
Audit Storage configuration.
@nklaassen nklaassen force-pushed the logan/byob-test-connection branch from 4a6acd9 to 97e60f1 Compare November 22, 2023 23:33
@nklaassen nklaassen enabled auto-merge November 22, 2023 23:33
@nklaassen nklaassen added this pull request to the merge queue Nov 22, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2023
@nklaassen nklaassen added this pull request to the merge queue Nov 23, 2023
Merged via the queue into master with commit fc2221d Nov 23, 2023
@nklaassen nklaassen deleted the logan/byob-test-connection branch November 23, 2023 00:50
@public-teleport-github-review-bot
Copy link
Copy Markdown

@logand22 See the table below for backport results.

Branch Result
branch/v14 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants