-
Notifications
You must be signed in to change notification settings - Fork 91
Say the RDS log was refused, instead of that it held no plans #2634
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* | ||
| * Copyright (c) 2026 Erik Darling, Darling Data LLC | ||
| * | ||
| * This file is part of the SQL Server Performance Monitor. | ||
| * | ||
| * Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
| */ | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Text.RegularExpressions; | ||
| using Npgsql; | ||
| using PerformanceMonitor.Darling.Service.Targets; | ||
| using Xunit; | ||
|
|
||
| namespace Darling.Tests; | ||
|
|
||
| /// <summary> | ||
| /// #2633: "could not read the log" and "read the log, it held nothing" were the same value, and the store | ||
| /// reported the second one. | ||
| /// | ||
| /// <para> | ||
| /// Measured on the PostgreSQL monitoring host after deploying the RDS log-API route. <c>collection_log</c> | ||
| /// said <c>SUCCESS | rows=0 | no new auto_explain plans in the RDS log window</c>. The app log said | ||
| /// <c>rds:DescribeDBLogFiles</c> was denied by IAM. Nothing had been read; the row asserted the log was | ||
| /// opened and was empty. | ||
| /// </para> | ||
| /// | ||
| /// <para> | ||
| /// It was also a REGRESSION against the route it replaced: <c>pg_read_file</c> answers the same situation | ||
| /// with <c>PERMISSIONS</c> and a message naming the grant. The managed path — the one a real fleet is on — | ||
| /// was the one that went quiet, and the app-log warning is not a substitute for the column collection | ||
| /// health is actually read from. | ||
| /// </para> | ||
| /// </summary> | ||
| public sealed class RdsLogUnavailableTests | ||
| { | ||
| /// <summary> | ||
| /// The message shape measured on the fleet, verbatim past the identifiers. Matched on the SENTENCE and | ||
| /// not only on an SDK exception type, because the refusal arrives in more than one shape depending on | ||
| /// the call. | ||
| /// </summary> | ||
| private const string FleetDenial = | ||
| "User: arn:aws:sts::000000000000:assumed-role/example-monitor-role/i-0example is not authorized to " | ||
| + "perform: rds:DescribeDBLogFiles on resource: arn:aws:rds:us-east-1:000000000000:db:example-1 " | ||
| + "because no identity-based policy allows the rds:DescribeDBLogFiles action"; | ||
|
|
||
| [Fact] | ||
| public void TheFleetsOwnDenialMessage_IsRecognisedAsAnAuthorizationRefusal() | ||
| => Assert.True(RdsLogUnavailableException.IsAuthorizationRefusal(new InvalidOperationException(FleetDenial))); | ||
|
|
||
| [Theory] | ||
| [InlineData("AccessDenied")] | ||
| [InlineData("AccessDeniedException: not authorised")] | ||
| [InlineData("User: x is not authorized to perform: rds:DownloadDBLogFilePortion")] | ||
| public void TheOtherShapesTheSdkUses_AreRecognisedToo(string message) | ||
| => Assert.True(RdsLogUnavailableException.IsAuthorizationRefusal(new InvalidOperationException(message))); | ||
|
|
||
| /// <summary> | ||
| /// It is found through the INNER exception too — the SDK wraps, and a refusal that arrives nested must | ||
| /// not be classified as an unknown fault and reported as a hard error. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ARefusalNestedInsideAWrapper_IsStillFound() | ||
| => Assert.True(RdsLogUnavailableException.IsAuthorizationRefusal( | ||
| new InvalidOperationException("reading the log failed", new InvalidOperationException(FleetDenial)))); | ||
|
|
||
| /// <summary> | ||
| /// And everything else stays LOUD. A throttle, a failover or an endpoint that stopped resolving is not | ||
| /// a configuration choice, and giving it a permanent-sounding status is how a real outage gets read as | ||
| /// one. The store's own rule: an unclassified failure must be loud rather than quietly swallowed. | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData("Rate exceeded")] | ||
| [InlineData("The DB instance is currently in a failover state")] | ||
| [InlineData("The specified DB instance was not found")] | ||
| [InlineData("A connection attempt failed")] | ||
| public void ATransientOrUnknownFailure_IsNotAnAuthorizationRefusal(string message) | ||
| => Assert.False(RdsLogUnavailableException.IsAuthorizationRefusal(new InvalidOperationException(message))); | ||
|
|
||
| [Fact] | ||
| public void TheExceptionCarriesTheClassificationAndTheOriginalMessage() | ||
| { | ||
| var inner = new InvalidOperationException(FleetDenial); | ||
|
|
||
| var ex = new RdsLogUnavailableException( | ||
| inner.Message, RdsLogUnavailableException.IsAuthorizationRefusal(inner), inner); | ||
|
|
||
| Assert.True(ex.IsAuthorizationFailure); | ||
| Assert.Same(inner, ex.InnerException); | ||
| Assert.Contains("rds:DescribeDBLogFiles", ex.Message, StringComparison.Ordinal); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The source pin on the half that caused the defect. The ingestor must not turn a failure into a row | ||
| /// COUNT: returning zero there is indistinguishable from an empty log one frame later, and the runner | ||
| /// stamps that with a sentence claiming the log was read. | ||
| /// </summary> | ||
| [Fact] | ||
| public void TheIngestorRethrows_RatherThanReturningZeroRowsOnFailure() | ||
| { | ||
| var source = File.ReadAllText(Path.Combine(RepoRoot(), | ||
| "Darling", "PerformanceMonitor.Darling.Service", "Targets", "RdsPlanIngestor.cs")); | ||
|
|
||
| var catchIndex = source.IndexOf("catch (Exception ex) when (ex is not OperationCanceledException)", StringComparison.Ordinal); | ||
| Assert.True(catchIndex >= 0, "The ingestor's tolerant catch is gone — this pin needs re-anchoring."); | ||
|
|
||
| var body = source[catchIndex..]; | ||
| var close = body.IndexOf("\n }", StringComparison.Ordinal); | ||
| body = close > 0 ? body[..close] : body; | ||
|
|
||
| Assert.Contains("throw new RdsLogUnavailableException", body, StringComparison.Ordinal); | ||
| Assert.DoesNotMatch(new Regex(@"return\s+0\s*;"), body); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// And the pin on the second defect: <c>IsAwsRds</c> was never assigned on the PostgreSQL connect path, | ||
| /// so <c>pg_plan_capture</c>'s <c>IsAurora || IsAwsRds</c> dispatch had an unreachable half and plain | ||
| /// RDS PostgreSQL — managed, no filesystem, not Aurora — fell to the <c>pg_read_file</c> route. | ||
| /// | ||
| /// <para>The fleet could never have shown this: every PostgreSQL target on it is Aurora, so | ||
| /// <c>IsAurora</c> carried the routing and the dead half was never load-bearing.</para> | ||
| /// </summary> | ||
| [Fact] | ||
| public void ThePostgresConnectPath_SetsIsAwsRds() | ||
| { | ||
| var source = File.ReadAllText(Path.Combine(RepoRoot(), | ||
| "Darling", "PerformanceMonitor.Darling.Service", "DarlingServerConnector.cs")); | ||
|
|
||
| var pgIndex = source.IndexOf("Engine = CollectorTargetEngine.PostgreSql,", StringComparison.Ordinal); | ||
| Assert.True(pgIndex >= 0, "The PostgreSQL target construction moved — this pin needs re-anchoring."); | ||
|
|
||
| var block = source[pgIndex..]; | ||
| var close = block.IndexOf("\n },", StringComparison.Ordinal); | ||
| block = close > 0 ? block[..close] : block; | ||
|
|
||
| Assert.Contains("IsAwsRds", block, StringComparison.Ordinal); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The derivation itself, against the endpoint shapes it has to separate. A managed host is RDS; a | ||
| /// self-hosted one is not, and must keep the file route that works there. | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData("example-1.abcdefghijkl.us-east-1.rds.amazonaws.com", true)] | ||
| [InlineData("example-cluster.cluster-abcdefghijkl.us-east-1.rds.amazonaws.com", true)] | ||
| [InlineData("localhost", false)] | ||
| [InlineData("db.internal.example.com", false)] | ||
| public void TheEndpointDecidesWhetherATargetIsManaged(string host, bool expected) | ||
| => Assert.Equal(expected, RdsEndpoint.TryParse(host) is not null); | ||
|
|
||
| private static string RepoRoot() | ||
| { | ||
| var directory = new DirectoryInfo(AppContext.BaseDirectory); | ||
| while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "PerformanceMonitor.sln"))) | ||
| { | ||
| directory = directory.Parent; | ||
| } | ||
|
|
||
| return directory?.FullName ?? throw new InvalidOperationException("PerformanceMonitor.sln not found above the test output directory."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes
Target.IsAwsRds(the fieldpg_plan_capture's dispatch reads), butConnectPostgresAsync's returnedServerRuntimenever sets the top-levelServerRuntime.IsAwsRds(DarlingServerConnector.cs:55) — onlyTarget.IsAwsRdsgets the derived value here. The SQL Server path sets both (isAwsRdsflows intoTarget.IsAwsRdsat line 297 andServerRuntime.IsAwsRdsat line 311); the new Postgres path only does the former.ProbeAsyncbuildsConnectionProbeResult.IsAwsRdsfromruntime.IsAwsRds(line 420), notruntime.Target.IsAwsRds, so for an actual RDS PostgreSQL targettest_connect/add_serverswill keep reportingisAwsRds: falseinDarlingCommandExecutor.MapProbeResult(line 481) even after this fix — while the collector loop's dispatch (DarlingWorker.cs:4711) correctly treats the same target as RDS. Operator-facing preflight output disagrees with actual runtime behavior for the exact fact this PR is about.No PostgreSQL collector currently gates
AppliesToonIsAwsRds, soDescribeProbeFacts's skipped-collector count isn't affected today, but the rawisAwsRdsJSON field returned bytest_connect/add_serversis directly wrong.Suggest also setting
IsAwsRdson the returnedServerRuntimehere, mirroring the SQL Server path.