Skip to content

Commit

Permalink
Revert "refactor: Use logging with context in Migrate"
Browse files Browse the repository at this point in the history
This reverts commit 2323ee2.
  • Loading branch information
romantmb committed Jan 21, 2025
1 parent 957ace2 commit 5ba0131
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 107 deletions.
39 changes: 21 additions & 18 deletions src/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private function restoreDestinationProject(array $restoreCredentials): void

private function migrateSecrets(): void
{
$this->logger->info('Migrating configurations with secrets');
$this->logger->info('Migrating configurations with secrets', ['secrets']);

$sourceDevBranches = new DevBranches($this->sourceProjectStorageClient);
$sourceBranches = $sourceDevBranches->listBranches();
Expand All @@ -192,28 +192,28 @@ private function migrateSecrets(): void
$sourceComponentsApi = new Components($this->sourceProjectStorageClient);
$components = $sourceComponentsApi->listComponents();
if (!$components) {
$this->logger->info('There are no components to migrate.');
$this->logger->info('There are no components to migrate.', ['secrets']);
return;
}

foreach ($components as $component) {
if (in_array($component['id'], self::OBSOLETE_COMPONENTS, true)) {
$this->logger->info('Components "{componentId}" is obsolete, skipping migration...', [
'componentId' => $component['id'],
]);
$this->logger->info(
sprintf('Components "%s" is obsolete, skipping migration...', $component['id']),
['secrets']
);
continue;
}

foreach ($component['configurations'] as $config) {
$this->logger->info(
sprintf(
'%sMigrating configuration "{configId}" of component "{componentId}"',
'%sMigrating configuration "%s" of component "%s"',
$this->dryRun ? '[dry-run] ' : '',
$config['id'],
$component['id'],
),
[
'configId' => $config['id'],
'componentId' => $component['id'],
],
['secrets'],
);

try {
Expand Down Expand Up @@ -256,11 +256,11 @@ private function migrateSecrets(): void
$message = '[dry-run] ' . $message;
}

$this->logger->info($message);
$this->logger->info($message, ['secrets']);

if (isset($response['warnings']) && is_array($response['warnings'])) {
foreach ($response['warnings'] as $warning) {
$this->logger->warning($warning);
$this->logger->warning($warning, ['secrets']);
}
}
}
Expand Down Expand Up @@ -399,12 +399,15 @@ private function preserveProperSnowflakeWorkspace(

$destinationComponentsApi->updateConfiguration($destinationConfiguration);

$this->logger->info('Used existing Snowflake workspace "{workspace}" '
. 'for configuration with ID "{configId}" ({componentId}).', [
'workspace' => $migratedWorkspaceParameters['user'],
'configId' => $destinationConfigurationId,
'componentId' => $destinationComponentId,
]);
$this->logger->info(
sprintf(
"Used existing Snowflake workspace '%s' for configuration with ID '%s' (%s).",
$migratedWorkspaceParameters['user'],
$destinationConfigurationId,
$destinationComponentId,
),
['secrets']
);
return;
}

Expand Down
158 changes: 69 additions & 89 deletions tests/phpunit/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,56 +332,45 @@ public function testMigrateSecretsSuccess(): void

$migrate->run();

self::assertTrue(
$logsHandler->hasInfo('Migrating configurations with secrets'),
$records = array_filter(
$logsHandler->getRecords(),
fn(array $record) => in_array('secrets', $record['context'] ?? [], true)
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Components "{componentId}" is obsolete, skipping migration...',
'context' => [
'componentId' => 'gooddata-writer',
],
]),
self::assertCount(8, $records);

$record = array_shift($records);
self::assertSame('Migrating configurations with secrets', $record['message']);
$record = array_shift($records);
self::assertSame('Components "gooddata-writer" is obsolete, skipping migration...', $record['message']);
$record = array_shift($records);
self::assertSame(
'Migrating configuration "101" of component "some-component"',
$record['message']
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '101',
'componentId' => 'some-component',
],
]),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'101\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'101\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Migrating configuration "102" of component "some-component"',
$record['message']
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '102',
'componentId' => 'some-component',
],
]),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'102\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'102\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Migrating configuration "201" of component "another-component"',
$record['message']
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '201',
'componentId' => 'another-component',
],
]),
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'201\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'201\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);
}

Expand Down Expand Up @@ -563,58 +552,49 @@ public function testMigrateSnowflakeWritersWithSharedWorkspacesSuccess(): void

$migrate->run();

self::assertTrue(
$logsHandler->hasInfo('Migrating configurations with secrets'),
$records = array_filter(
$logsHandler->getRecords(),
fn(array $record) => in_array('secrets', $record['context'] ?? [], true)
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '101',
'componentId' => 'keboola.wr-db-snowflake',
],
]),
self::assertCount(8, $records);

$record = array_shift($records);
self::assertSame('Migrating configurations with secrets', $record['message']);
$record = array_shift($records);
self::assertSame(
'Migrating configuration "101" of component "keboola.wr-db-snowflake"',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'101\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'101\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '102',
'componentId' => 'keboola.wr-db-snowflake',
],
]),
$record = array_shift($records);
self::assertSame(
'Migrating configuration "102" of component "keboola.wr-db-snowflake"',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'102\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'102\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);

self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Migrating configuration "{configId}" of component "{componentId}"',
'context' => [
'configId' => '102',
'componentId' => 'keboola.wr-db-snowflake',
],
]),
$record = array_shift($records);
self::assertSame(
'Migrating configuration "103" of component "keboola.wr-db-snowflake"',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo([
'message' => 'Used existing Snowflake workspace "{workspace}" for configuration '
. 'with ID "{configId}" ({componentId}).',
'context' => [
'workspace' => 'USER_01',
'configId' => '103',
'componentId' => 'keboola.wr-db-snowflake',
],
]),
$record = array_shift($records);
self::assertSame(
'Used existing Snowflake workspace \'USER_01\' for configuration with ID \'103\' '
. '(keboola.wr-db-snowflake).',
$record['message']
);
self::assertTrue(
$logsHandler->hasInfo('Configuration with ID \'103\' successfully migrated to stack \'dest-stack\'.'),
$record = array_shift($records);
self::assertSame(
'Configuration with ID \'103\' successfully migrated to stack \'dest-stack\'.',
$record['message']
);
}

Expand Down

0 comments on commit 5ba0131

Please sign in to comment.