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

feat: Add CloudWatch dashboard #541

Merged
merged 3 commits into from
Aug 12, 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
5 changes: 5 additions & 0 deletions docs/guide/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ To run the tests (Replace the url with the one you used in the steps above)
REACT_APP_URL=https://dxxxxxxxxxxxxx.cloudfront.net pytest integtests/
```

## Monitoring

Once the deployment is complete, a [CloudWatch Dashboard](https://console.aws.amazon.com/cloudwatch) will be available in the selected region to monitor the usage of the resources.


## Run user interface locally

To experiment with changes to the the user interface, you can run the interface locally. See the instructions in the README file of the [`lib/user-interface/react-app`](https://github.com/aws-samples/aws-genai-llm-chatbot/blob/main/lib/user-interface/react-app/README.md) folder.
Expand Down
59 changes: 47 additions & 12 deletions lib/aws-genai-llm-chatbot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import { SystemConfig, ModelInterface, Direction } from "./shared/types";
import { Authentication } from "./authentication";
import { Monitoring } from "./monitoring";
import { UserInterface } from "./user-interface";
import { Shared } from "./shared";
import { ChatBotApi } from "./chatbot-api";
Expand Down Expand Up @@ -66,19 +67,16 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
);

// check if any deployed model requires langchain interface or if bedrock is enabled from config
let langchainInterface: LangChainInterface | undefined;
if (langchainModels.length > 0 || props.config.bedrock?.enabled) {
const langchainInterface = new LangChainInterface(
this,
"LangchainInterface",
{
shared,
config: props.config,
ragEngines,
messagesTopic: chatBotApi.messagesTopic,
sessionsTable: chatBotApi.sessionsTable,
byUserIdIndex: chatBotApi.byUserIdIndex,
}
);
langchainInterface = new LangChainInterface(this, "LangchainInterface", {
shared,
config: props.config,
ragEngines,
messagesTopic: chatBotApi.messagesTopic,
sessionsTable: chatBotApi.sessionsTable,
byUserIdIndex: chatBotApi.byUserIdIndex,
});

// Route all incoming messages targeted to langchain to the langchain model interface queue
chatBotApi.messagesTopic.addSubscription(
Expand Down Expand Up @@ -218,6 +216,43 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
}
}

const monitoringStack = new cdk.NestedStack(this, "MonitoringStack");
new Monitoring(monitoringStack, "Monitoring", {
appsycnApi: chatBotApi.graphqlApi,
cognito: {
userPoolId: authentication.userPool.userPoolId,
clientId: authentication.userPoolClient.userPoolClientId,
},
tables: [
chatBotApi.sessionsTable,
...(ragEngines
? [ragEngines.workspacesTable, ragEngines.documentsTable]
: []),
],
sqs: [
chatBotApi.outBoundQueue,
ideficsInterface.ingestionQueue,
...(langchainInterface ? [langchainInterface.ingestionQueue] : []),
],
aurora: ragEngines?.auroraPgVector?.database,
opensearch: ragEngines?.openSearchVector?.openSearchCollection,
kendra: ragEngines?.kendraRetrieval?.kendraIndex,
buckets: [chatBotApi.filesBucket],
ragFunctionProcessing: [
...(ragEngines ? [ragEngines.dataImport.rssIngestorFunction] : []),
],
ragStateMachineProcessing: [
...(ragEngines
? [
ragEngines.dataImport.fileImportWorkflow,
ragEngines.dataImport.websiteCrawlingWorkflow,
ragEngines.deleteDocumentWorkflow,
ragEngines.deleteWorkspaceWorkflow,
]
: []),
],
});

/**
* CDK NAG suppression
*/
Expand Down
3 changes: 3 additions & 0 deletions lib/chatbot-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cognito from "aws-cdk-lib/aws-cognito";
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as sqs from "aws-cdk-lib/aws-sqs";
import * as sns from "aws-cdk-lib/aws-sns";
import * as ssm from "aws-cdk-lib/aws-ssm";
import * as iam from "aws-cdk-lib/aws-iam";
Expand Down Expand Up @@ -29,6 +30,7 @@ export interface ChatBotApiProps {

export class ChatBotApi extends Construct {
public readonly messagesTopic: sns.Topic;
public readonly outBoundQueue: sqs.Queue;
public readonly sessionsTable: dynamodb.Table;
public readonly byUserIdIndex: string;
public readonly filesBucket: s3.Bucket;
Expand Down Expand Up @@ -116,6 +118,7 @@ export class ChatBotApi extends Construct {
});

this.messagesTopic = realtimeBackend.messagesTopic;
this.outBoundQueue = realtimeBackend.queue;
this.sessionsTable = chatTables.sessionsTable;
this.byUserIdIndex = chatTables.byUserIdIndex;
this.userFeedbackBucket = chatBuckets.userFeedbackBucket;
Expand Down
2 changes: 2 additions & 0 deletions lib/chatbot-api/websocket-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface RealtimeGraphqlApiBackendProps {
export class RealtimeGraphqlApiBackend extends Construct {
public readonly messagesTopic: sns.Topic;
public readonly resolvers: RealtimeResolvers;
public readonly queue: sqs.Queue;

constructor(
scope: Construct,
Expand Down Expand Up @@ -80,6 +81,7 @@ export class RealtimeGraphqlApiBackend extends Construct {

this.messagesTopic = messagesTopic;
this.resolvers = resolvers;
this.queue = queue;

/**
* CDK NAG suppression
Expand Down
2 changes: 1 addition & 1 deletion lib/model-interfaces/idefics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class IdeficsInterface extends Construct {
const deadLetterQueue = new sqs.Queue(this, "DLQ", {
enforceSSL: true,
});
const queue = new sqs.Queue(this, "Queue", {
const queue = new sqs.Queue(this, "IdeficsIngestionQueue", {
removalPolicy: cdk.RemovalPolicy.DESTROY,
// https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-queueconfig
visibilityTimeout: cdk.Duration.minutes(lambdaDurationInMinutes * 6),
Expand Down
2 changes: 1 addition & 1 deletion lib/model-interfaces/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class LangChainInterface extends Construct {
enforceSSL: true,
});

const queue = new sqs.Queue(this, "Queue", {
const queue = new sqs.Queue(this, "LangChainIngestionQueue", {
removalPolicy: cdk.RemovalPolicy.DESTROY,
// https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-queueconfig
visibilityTimeout: cdk.Duration.minutes(15 * 6),
Expand Down
Loading
Loading