-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add rocket function app names to main function env vars * Add sensors for rockets * Correct app settings for event hub function app * Add rush change file * Update pnpm-lock.yaml * Update pnpm-lock.yaml * Update docs and English grammar corrections * Handle case for app that doesn't have any rockets --------- Co-authored-by: Castro, Mario <[email protected]>
- Loading branch information
Showing
21 changed files
with
325 additions
and
135 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@boostercloud/framework-core/rocket_health_sensors_2024-08-19-17-06.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@boostercloud/framework-core", | ||
"comment": "Health sensors for Rockets", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@boostercloud/framework-core" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
52 changes: 52 additions & 0 deletions
52
packages/framework-core/src/sensor/health/health-indicators/rockets-health-indicator.ts
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,52 @@ | ||
import { | ||
BOOSTER_HEALTH_INDICATORS_IDS, | ||
BoosterConfig, | ||
HealthIndicatorMetadata, | ||
HealthIndicatorsResult, | ||
HealthStatus, | ||
} from '@boostercloud/framework-types' | ||
|
||
export class RocketsHealthIndicator { | ||
public async health( | ||
config: BoosterConfig, | ||
healthIndicatorMetadata: HealthIndicatorMetadata | ||
): Promise<HealthIndicatorsResult> { | ||
const results = await config.provider.sensor.areRocketFunctionsUp(config) | ||
if (Object.keys(results).length === 0) { | ||
return { | ||
name: 'Rockets', | ||
id: BOOSTER_HEALTH_INDICATORS_IDS.ROCKETS, | ||
status: HealthStatus.UNKNOWN, | ||
details: { | ||
reason: 'No Rockets found', | ||
}, | ||
} | ||
} | ||
return { | ||
name: 'Rockets', | ||
id: BOOSTER_HEALTH_INDICATORS_IDS.ROCKETS, | ||
status: this.getOverAllHealthStatus(results), | ||
components: Object.entries(results).map(([rocketFunctionApp, status]) => { | ||
return { | ||
name: rocketFunctionApp, | ||
id: rocketFunctionApp, // @TODO: put the rocket's id instead of its name | ||
status: status ? HealthStatus.UP : HealthStatus.DOWN, | ||
} | ||
}), | ||
} | ||
} | ||
|
||
private getOverAllHealthStatus(results: { [key: string]: boolean }): HealthStatus { | ||
const statusValues = Object.values(results) | ||
|
||
if (statusValues.every((status) => status)) { | ||
return HealthStatus.UP | ||
} | ||
|
||
if (statusValues.every((status) => !status)) { | ||
return HealthStatus.DOWN | ||
} | ||
|
||
return HealthStatus.PARTIALLY_UP | ||
} | ||
} |
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
29 changes: 28 additions & 1 deletion
29
packages/framework-provider-azure-infrastructure/src/infrastructure/azure-stack.ts
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 |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import { Construct } from 'constructs' | ||
import { TerraformStack } from 'cdktf' | ||
import { Fn, TerraformStack } from 'cdktf' | ||
import { ApplicationSynth } from './synth/application-synth' | ||
import { ApplicationSynthStack } from './types/application-synth-stack' | ||
import { InfrastructureRocket } from './rockets/infrastructure-rocket' | ||
import { environmentVarNames } from '@boostercloud/framework-provider-azure' | ||
|
||
export class AzureStack extends TerraformStack { | ||
readonly applicationStack: ApplicationSynthStack | ||
readonly defaultApplicationSettings: { [key: string]: string } | ||
|
||
constructor(scope: Construct, name: string, zipFile?: string) { | ||
super(scope, name) | ||
|
||
const applicationSynth = new ApplicationSynth(this) | ||
this.applicationStack = applicationSynth.synth(zipFile) | ||
this.defaultApplicationSettings = applicationSynth.buildDefaultAppSettings( | ||
this.applicationStack, | ||
this.applicationStack.storageAccount!, | ||
'func' | ||
) | ||
} | ||
|
||
public addAppSettingsToFunctionApp(rockets?: InfrastructureRocket[]): void { | ||
if (!this.applicationStack.functionApp) { | ||
throw new Error('Function app not defined') | ||
} | ||
|
||
const functionAppNames = rockets | ||
? rockets | ||
.map((rocket: InfrastructureRocket) => | ||
rocket.getFunctionAppName ? rocket.getFunctionAppName(this.applicationStack) : '' | ||
) | ||
.join(',') | ||
: '' | ||
|
||
this.applicationStack.functionApp.appSettings = Fn.merge([ | ||
this.defaultApplicationSettings, | ||
{ [environmentVarNames.rocketFunctionAppNames]: functionAppNames }, | ||
]) | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...provider-azure-infrastructure/src/infrastructure/synth/terraform-function-app-settings.ts
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,40 @@ | ||
import { environmentVarNames } from '@boostercloud/framework-provider-azure' | ||
import { ApplicationSynthStack } from '../types/application-synth-stack' | ||
import { toTerraformName } from '../helper/utils' | ||
import { BoosterConfig } from '@boostercloud/framework-types' | ||
import { storageAccount } from '@cdktf/provider-azurerm' | ||
|
||
export class TerraformFunctionAppSettings { | ||
static build( | ||
{ appPrefix, cosmosdbDatabase, domainNameLabel, eventHubNamespace, eventHub, webPubSub }: ApplicationSynthStack, | ||
config: BoosterConfig, | ||
storageAccount: storageAccount.StorageAccount, | ||
suffixName: string | ||
): { [key: string]: string } { | ||
if (!cosmosdbDatabase) { | ||
throw new Error('Undefined cosmosdbDatabase resource') | ||
} | ||
const id = toTerraformName(appPrefix, suffixName) | ||
const eventHubConnectionString = | ||
eventHubNamespace?.defaultPrimaryConnectionString && eventHub?.name | ||
? `${eventHubNamespace.defaultPrimaryConnectionString};EntityPath=${eventHub.name}` | ||
: '' | ||
const region = (process.env['REGION'] ?? '').toLowerCase().replace(/ /g, '') | ||
return { | ||
WEBSITE_RUN_FROM_PACKAGE: '1', | ||
WEBSITE_CONTENTSHARE: id, | ||
...config.env, | ||
WebPubSubConnectionString: webPubSub?.primaryConnectionString || '', | ||
BOOSTER_ENV: config.environmentName, | ||
[environmentVarNames.restAPIURL]: `http://${domainNameLabel}.${region}.cloudapp.azure.com/${config.environmentName}`, | ||
[environmentVarNames.eventHubConnectionString]: eventHubConnectionString, | ||
[environmentVarNames.eventHubName]: config.resourceNames.streamTopic, | ||
[environmentVarNames.eventHubMaxRetries]: | ||
config.eventStreamConfiguration.parameters?.maxRetries?.toString() || '5', | ||
[environmentVarNames.eventHubMode]: config.eventStreamConfiguration.parameters?.mode || 'exponential', | ||
COSMOSDB_CONNECTION_STRING: `AccountEndpoint=https://${cosmosdbDatabase.name}.documents.azure.com:443/;AccountKey=${cosmosdbDatabase.primaryKey};`, | ||
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING: storageAccount.primaryConnectionString, // Terraform bug: https://github.com/hashicorp/terraform-provider-azurerm/issues/16650 | ||
BOOSTER_APP_NAME: process.env['BOOSTER_APP_NAME'] ?? '', | ||
} | ||
} | ||
} |
Oops, something went wrong.