-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Query Store top queries tab. Using messaging system to get data directly from query store on monitored instances.
- Loading branch information
1 parent
4c097bf
commit c52d25e
Showing
27 changed files
with
2,172 additions
and
192 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,54 @@ | ||
using Microsoft.Data.SqlClient; | ||
using Serilog; | ||
using SerilogTimings; | ||
using System; | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
|
||
namespace DBADash.Messaging | ||
{ | ||
public class PlanCollectionMessage : MessageBase | ||
{ | ||
public string ConnectionID { get; set; } | ||
public string DatabaseName { get; set; } | ||
|
||
public long PlanID { get; set; } | ||
|
||
public override async Task<DataSet> Process(CollectionConfig cfg, Guid handle) | ||
{ | ||
if (IsExpired) | ||
{ | ||
throw new Exception("Message expired"); | ||
} | ||
|
||
using var op = Operation.Begin( | ||
"Get Plan ID {id} from {database} on {instance} triggered from message {handle}", | ||
PlanID, | ||
DatabaseName, | ||
ConnectionID, | ||
handle); | ||
try | ||
{ | ||
var src = cfg.GetSourceConnection(ConnectionID); | ||
var builder = new SqlConnectionStringBuilder(src.SourceConnection.ConnectionString) | ||
{ | ||
InitialCatalog = DatabaseName | ||
}; | ||
await using var cn = new SqlConnection(builder.ConnectionString); | ||
await cn.OpenAsync(); | ||
await using var cmd = | ||
new SqlCommand("SELECT query_plan FROM sys.query_store_plan WHERE plan_id = @plan_id", cn); | ||
cmd.Parameters.AddWithValue("@plan_id", PlanID); | ||
using var da = new SqlDataAdapter(cmd); | ||
var ds = new DataSet(); | ||
da.Fill(ds); | ||
return ds; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error(ex, "Plan collection request from {handle} failed", handle); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.