Skip to content
Open
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
111 changes: 60 additions & 51 deletions src/components/web-server/README.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/components/web-server/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class WebServerBuilder {
private _hostedZoneId?: pulumi.Input<string>;
private _certificate?: pulumi.Input<aws.acm.Certificate>;
private _healthCheckPath?: pulumi.Input<string>;
private _healthCheckConfig?: WebServer.Args['healthCheckConfig'];
private _loadBalancingAlgorithmType?: pulumi.Input<string>;
private _otelCollector?: pulumi.Input<OtelCollector>;
private _initContainers: pulumi.Input<WebServer.InitContainer>[] = [];
Expand Down Expand Up @@ -112,10 +113,12 @@ export class WebServerBuilder {
return this;
}

public withCustomHealthCheckPath(
public withHealthCheck(
path: WebServer.Args['healthCheckPath'],
config?: WebServer.Args['healthCheckConfig'],
): this {
this._healthCheckPath = path;
this._healthCheckConfig = config;

return this;
}
Expand Down Expand Up @@ -154,6 +157,7 @@ export class WebServerBuilder {
hostedZoneId: this._hostedZoneId,
certificate: this._certificate,
healthCheckPath: this._healthCheckPath,
healthCheckConfig: this._healthCheckConfig,
loadBalancingAlgorithmType: this._loadBalancingAlgorithmType,
otelCollector: this._otelCollector,
initContainers: this._initContainers,
Expand Down
5 changes: 5 additions & 0 deletions src/components/web-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export namespace WebServer {
* "/healthcheck"
*/
healthCheckPath?: pulumi.Input<string>;
healthCheckConfig?: Omit<
aws.types.input.lb.TargetGroupHealthCheck,
'path'
>;
loadBalancingAlgorithmType?: pulumi.Input<string>;
initContainers?: pulumi.Input<pulumi.Input<WebServer.InitContainer>[]>;
sidecarContainers?: pulumi.Input<
Expand Down Expand Up @@ -133,6 +137,7 @@ export class WebServer extends pulumi.ComponentResource {
port: args.port,
certificate: certificate ?? this.acmCertificate?.certificate,
healthCheckPath: args.healthCheckPath,
healthCheckConfig: args.healthCheckConfig,
loadBalancingAlgorithmType: args.loadBalancingAlgorithmType,
},
{
Expand Down
23 changes: 17 additions & 6 deletions src/components/web-server/load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export namespace WebServerLoadBalancer {
port: pulumi.Input<number>;
certificate?: pulumi.Input<aws.acm.Certificate>;
healthCheckPath?: pulumi.Input<string>;
healthCheckConfig?: Omit<aws.types.input.lb.TargetGroupHealthCheck, 'path'>;
loadBalancingAlgorithmType?: pulumi.Input<string>;
};
}
Expand Down Expand Up @@ -41,6 +42,12 @@ const webServerLoadBalancerNetworkConfig = {

const defaults = {
healthCheckPath: '/healthcheck',
healthCheckConfig: {
healthyThreshold: 3,
unhealthyThreshold: 2,
interval: 60,
timeout: 5,
},
};

export class WebServerLoadBalancer extends pulumi.ComponentResource {
Expand All @@ -61,8 +68,13 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
this.name = name;
const vpc = pulumi.output(args.vpc);
const argsWithDefaults = mergeWithDefaults(defaults, args);
const { port, certificate, healthCheckPath, loadBalancingAlgorithmType } =
argsWithDefaults;
const {
port,
certificate,
healthCheckPath,
healthCheckConfig,
loadBalancingAlgorithmType,
} = argsWithDefaults;

this.securityGroup = this.createLbSecurityGroup(vpc.vpcId);

Expand All @@ -84,6 +96,7 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
port,
vpc.vpcId,
healthCheckPath,
healthCheckConfig,
loadBalancingAlgorithmType,
);
this.httpListener = this.createLbHttpListener(
Expand Down Expand Up @@ -163,6 +176,7 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
port: pulumi.Input<number>,
vpcId: awsx.ec2.Vpc['vpcId'],
healthCheckPath: pulumi.Input<string>,
healthCheckConfig: WebServerLoadBalancer.Args['healthCheckConfig'],
loadBalancingAlgorithmType?: pulumi.Input<string>,
): aws.lb.TargetGroup {
return new aws.lb.TargetGroup(
Expand All @@ -175,10 +189,7 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
vpcId,
loadBalancingAlgorithmType,
healthCheck: {
healthyThreshold: 3,
unhealthyThreshold: 2,
interval: 60,
timeout: 5,
...healthCheckConfig,
path: healthCheckPath,
},
tags: { ...commonTags, Name: `${this.name}-target-group` },
Expand Down
4 changes: 2 additions & 2 deletions tests/build/index.tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ describe('Build output', () => {
);
});

it('should have withCustomHealthCheckPath method', () => {
expect(builder.withCustomHealthCheckPath).type.toBeCallableWith(
it('should have withHealthCheck method', () => {
expect(builder.withHealthCheck).type.toBeCallableWith(
'/custom/healthCheck/path',
);
});
Expand Down
10 changes: 10 additions & 0 deletions tests/web-server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ describe('Web server component deployment', () => {
ctx.config.healthCheckPath,
'Target group should have correct health check path',
);
assert.deepStrictEqual(
{
healthyThreshold: tg.HealthyThresholdCount,
unhealthyThreshold: tg.UnhealthyThresholdCount,
interval: tg.HealthCheckIntervalSeconds,
timeout: tg.HealthCheckTimeoutSeconds,
},
ctx.config.healthCheckConfig,
'Target group should have correct health check configuration',
);

const attributesCommand = new DescribeTargetGroupAttributesCommand({
TargetGroupArn: webServer.lb.targetGroup.arn,
Expand Down
11 changes: 10 additions & 1 deletion tests/web-server/infrastructure/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
export const webServerName = 'web-server-test';
export const healthCheckPath = '/healthcheck';

export const webServerImageName = 'nginxdemos/nginx-hello:plain-text';

export const webServerPort = 8080;

export const healthCheckPath = '/healthcheck';

export const healthCheckConfig = {
healthyThreshold: 5,
unhealthyThreshold: 3,
interval: 15,
timeout: 3,
};

const baseDomain = `ws.${process.env.ICB_DOMAIN_NAME!}`;

export const webServerWithDomainConfig = {
Expand Down
9 changes: 5 additions & 4 deletions tests/web-server/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as util from '../../util';
import {
webServerName,
healthCheckPath,
healthCheckConfig,
webServerWithDomainConfig,
webServerWithSanCertificateConfig,
webServerWithCertificateConfig,
Expand Down Expand Up @@ -68,7 +69,7 @@ const webServer = new studion.WebServerBuilder(webServerName)
.addSidecarContainer(sidecar)
.withVpc(vpc.vpc)
.withOtelCollector(otelCollector)
.withCustomHealthCheckPath(healthCheckPath)
.withHealthCheck(healthCheckPath, healthCheckConfig)
.withLoadBalancingAlgorithm('least_outstanding_requests')
.build({ parent: cluster });

Expand All @@ -81,7 +82,7 @@ const webServerWithDomain = new studion.WebServerBuilder(`web-server-domain`)
.withContainer(webServerImageName, 8080)
.withEcsConfig(ecs)
.withVpc(vpc.vpc)
.withCustomHealthCheckPath(healthCheckPath)
.withHealthCheck(healthCheckPath)
.withCustomDomain(webServerWithDomainConfig.primary, hostedZone.zoneId)
.build({ parent: cluster });

Expand All @@ -100,7 +101,7 @@ const webServerWithSanCertificate = new studion.WebServerBuilder(
.withContainer(webServerImageName, 8080)
.withEcsConfig(ecs)
.withVpc(vpc.vpc)
.withCustomHealthCheckPath(healthCheckPath)
.withHealthCheck(healthCheckPath)
.withCertificate(sanWebServerCert.certificate, hostedZone.zoneId)
.build({
parent: cluster,
Expand All @@ -120,7 +121,7 @@ const webServerWithCertificate = new studion.WebServerBuilder(`web-server-cert`)
.withContainer(webServerImageName, 8080)
.withEcsConfig(ecs)
.withVpc(vpc.vpc)
.withCustomHealthCheckPath(healthCheckPath)
.withHealthCheck(healthCheckPath)
.withCertificate(
certWebServer.certificate,
hostedZone.zoneId,
Expand Down
10 changes: 7 additions & 3 deletions tests/web-server/test-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { Route53Client } from '@aws-sdk/client-route-53';
interface WebServerTestConfig {
webServerName: string;
healthCheckPath: string;
healthCheckConfig: {
healthyThreshold: number;
unhealthyThreshold: number;
interval: number;
timeout: number;
};
webServerImageName: string;
webServerPort: number;
webServerWithDomainConfig: {
Expand Down Expand Up @@ -42,6 +48,4 @@ interface AwsContext {
}

export interface WebServerTestContext
extends ConfigContext,
PulumiProgramContext,
AwsContext {}
extends ConfigContext, PulumiProgramContext, AwsContext {}