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

Normalize ah_env telemetry. #1742

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/Helpers/TelemetryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@
}
}

/**
* @param string $ah_env
* Environment name from AH_ENV.
* @return string
* Normalized environment name.
*/
public static function normalizeAhEnv(string $ah_env): string {
if (AcquiaDrupalEnvironmentDetector::isAhProdEnv($ah_env)) {
return 'prod';
}
if (AcquiaDrupalEnvironmentDetector::isAhStageEnv($ah_env)) {
return 'stage';
}
if (AcquiaDrupalEnvironmentDetector::isAhDevEnv($ah_env)) {
return 'dev';
}
if (AcquiaDrupalEnvironmentDetector::isAhOdeEnv($ah_env)) {
return 'ode';
}
if (AcquiaDrupalEnvironmentDetector::isAhIdeEnv($ah_env)) {
return 'ide';
}
return $ah_env;
}

/**
* Get telemetry user data.
*
Expand All @@ -115,7 +140,7 @@
private function getTelemetryUserData(): array {
$data = [
'ah_app_uuid' => getenv('AH_APPLICATION_UUID'),
'ah_env' => AcquiaDrupalEnvironmentDetector::getAhEnv(),
'ah_env' => $this->normalizeAhEnv(AcquiaDrupalEnvironmentDetector::getAhEnv()),

Check warning on line 143 in src/Helpers/TelemetryHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/TelemetryHelper.php#L143

Added line #L143 was not covered by tests
'ah_group' => AcquiaDrupalEnvironmentDetector::getAhGroup(),
'ah_non_production' => getenv('AH_NON_PRODUCTION'),
'ah_realm' => getenv('AH_REALM'),
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/src/Misc/TelemetryHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,33 @@ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void {
$this->assertNull(TelemetryHelper::getEnvironmentProvider());
}

/**
* @return mixed[]
* The data provider.
*/
public function providerTestAhEnvNormalization(): array {
return [
['prod', 'prod'],
['01live', 'prod'],
['stage', 'stage'],
['stg', 'stage'],
['dev1', 'dev'],
['ode1', 'ode'],
['ide', 'ide'],
['fake', 'fake'],
];
}

/**
* @dataProvider providerTestAhEnvNormalization
* @param string $ah_env
* The Acquia hosting environment.
* @param string $expected
* The expected normalized environment.
*/
public function testAhEnvNormalization(string $ah_env, string $expected): void {
$normalized_ah_env = TelemetryHelper::normalizeAhEnv($ah_env);
$this->assertEquals($expected, $normalized_ah_env);
}

}