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

Trigger collection support on various tabs #916

Merged
merged 11 commits into from
Jun 22, 2024
29 changes: 22 additions & 7 deletions DBADash/Messaging/CollectionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class CollectionMessage : MessageBase

public string ConnectionID { get; set; }

public string DatabaseName { get; set; }

public CollectionMessage(List<string> collectionTypes, string connectionID)
{
CollectionTypes = collectionTypes;
Expand Down Expand Up @@ -60,17 +62,30 @@ public override async Task<DataSet> Process(CollectionConfig cfg, Guid handle)

var (standardCollections, customCollections) = ParseCollectionTypes(src, cfg);

if (standardCollections.Contains(CollectionType.SchemaSnapshot))
{
// Written to destinations as usual. Could be additional delay to process.
// It's done DB at a time to limit the size of the data being processed.
await SchemaSnapshotDB.GenerateSchemaSnapshots(cfg, src);
}

var collector = new DBCollector(src, cfg.ServiceName, true);
collector.Collect(standardCollections.ToArray());
collector.Collect(customCollections);

if (standardCollections.Contains(CollectionType.SchemaSnapshot))
{

if (string.IsNullOrEmpty(DatabaseName)) //
{
// Snapshot all configured databases
// Written to destinations as usual. Could be additional delay to process.
// It's done DB at a time to limit the size of the data being processed.
Log.Information("Message {handle} requested schema snapshots for {instance}", handle,ConnectionID);
await SchemaSnapshotDB.GenerateSchemaSnapshots(cfg, src);
}
else
{
Log.Information("Message {handle} requested snapshot for database {DatabaseName} on {instance}", handle,DatabaseName,ConnectionID);
var schema = new SchemaSnapshotDB(src.SourceConnection, cfg.SchemaSnapshotOptions);
var dt = schema.SnapshotDB(DatabaseName);
collector.Data.Tables.Add(dt);
}
}

if (CollectAgent.S3Path != null)
{
op.Complete();
Expand Down
15 changes: 8 additions & 7 deletions DBADash/SchemaSnapshotDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public static string ObjectDDL(string connectionString, string objectName)

public DataTable SnapshotDB(string DBName)
{
var StartTime = DateTime.UtcNow;

using (var cn = new Microsoft.Data.SqlClient.SqlConnection(ConnectionString))
using (var opSS = Operation.Begin("Schema snapshot {DBame}", DBName))
{
Expand Down Expand Up @@ -362,6 +364,11 @@ public DataTable SnapshotDB(string DBName)
}
}
opSS.Complete();
var EndTime = DateTime.UtcNow;
dtSchema.TableName = "Snapshot_" + DBName;
dtSchema.ExtendedProperties.Add("StartTimeBin", StartTime.ToBinary().ToString());
dtSchema.ExtendedProperties.Add("EndTimeBin", EndTime.ToBinary().ToString());
dtSchema.ExtendedProperties.Add("SnapshotOptions", JsonConvert.SerializeObject(options));
return dtSchema;
}
}
Expand Down Expand Up @@ -1005,17 +1012,11 @@ public static async Task GenerateSchemaSnapshots(CollectionConfig Config, DBADas
if (!include) continue;

Log.Information("DB Snapshot {db} from instance {instance}", db.Name, builder.DataSource);
var StartTime = DateTime.UtcNow;

try
{
var dt = ss.SnapshotDB(db.Name);
var EndTime = DateTime.UtcNow;
dt.TableName = "Snapshot_" + db.Name;
dt.ExtendedProperties.Add("StartTimeBin", StartTime.ToBinary().ToString());
dt.ExtendedProperties.Add("EndTimeBin", EndTime.ToBinary().ToString());
dt.ExtendedProperties.Add("SnapshotOptions", JsonConvert.SerializeObject(Config.SchemaSnapshotOptions));
dsSnapshot.Tables.Add(dt);

var fileName = DBADashSource.GenerateFileName(src.SourceConnection.ConnectionForFileName);
await DestinationHandling.WriteAllDestinations(dsSnapshot, src, fileName, Config);
dsSnapshot.Tables.Remove(dt);
Expand Down
3 changes: 2 additions & 1 deletion DBADashDB/dbo/Stored Procedures/DDLSnapshots_Get.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@PageNumber INT=1
)
AS
SELECT I.InstanceGroupName,
SELECT I.InstanceID,
I.InstanceGroupName,
ss.DatabaseID,
ss.SnapshotDate,
ss.ValidatedDate,
Expand Down
Loading