Skip to content

Commit

Permalink
Fixed getting the service name for SST services
Browse files Browse the repository at this point in the history
  • Loading branch information
boristane committed Aug 19, 2023
1 parent 136c7a6 commit 1997c13
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixed
- Fix getting the service name for SST services

## [0.0.41] 2023-08-12
### Fixed
Expand Down
4 changes: 1 addition & 3 deletions src/resources/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { CfnResource, Stack } from "aws-cdk-lib";
import { Baselime as Config } from "../config";
import { Query } from "./query";
import { AlertProps, DeploymentAlertParameters } from "../types/alert";
import { QueryProps } from "../types/query";
import { getServiceName } from "../utils/service-name";

export class Alert<TKey extends string> extends CfnResource {

constructor(id: string, props: AlertProps<TKey>) {
const stack = Stack.of(Config.getConstruct());
const defaultFrequency = "1hour";
const defaultWindow = "1hour";

Expand Down Expand Up @@ -55,7 +53,7 @@ export class Alert<TKey extends string> extends CfnResource {
BaselimeApiKey: Config.getApiKey(),
enabled: props.enabled,
Description: props.description,
Service: getServiceName(stack),
Service: getServiceName(),
Parameters,
Channels: props.channels || Config.getDefaultChannel() && [Config.getDefaultChannel()],
Origin: "cdk",
Expand Down
3 changes: 1 addition & 2 deletions src/resources/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getServiceName } from "../utils/service-name";

export class Dashboard extends CfnResource {
constructor(id: string, props: DashboardProps) {
const stack = Stack.of(Config.getConstruct());

const parameters = {
...props.parameters,
Expand All @@ -20,7 +19,7 @@ export class Dashboard extends CfnResource {
ServiceToken: Config.getServiceToken(),
BaselimeApiKey: Config.getApiKey(),
Description: props.description,
Service: getServiceName(stack),
Service: getServiceName(),
Parameters: parameters,
Origin: "cdk"
},
Expand Down
2 changes: 1 addition & 1 deletion src/resources/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Query<TKey extends string> extends CfnResource {
ServiceToken: Config.getServiceToken(),
BaselimeApiKey: Config.getApiKey(),
Description: props.description,
Service: getServiceName(stack),
Service: getServiceName(),
Parameters,
Origin: "cdk"
},
Expand Down
15 changes: 9 additions & 6 deletions src/utils/service-name.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Stack } from "aws-cdk-lib";
import { Baselime as Config } from "../config";

export function getServiceName(stack: Stack): string {
export function getServiceName(): string {
const s = Config.getServiceName();
if (s) {
return s;
}
const tags = stack.tags.tagValues();

const isSST = Object.keys(tags).some((el) => el.includes("sst"));
const construct = Config.getConstruct();
const root = construct.node.root as any;

if (isSST) {
return `${tags['sst:stage']}-${tags['sst:app']}`;
}
const stage = root.stage;
const name = root.name;

if (stage && name) {
return `${stage}-${name}`;
}
const stack = Stack.of(construct);
return stack.stackName;
}

0 comments on commit 1997c13

Please sign in to comment.