1 00:00:00,690 --> 00:00:02,760 ‫So let's practice using X-Ray. 2 00:00:02,760 --> 00:00:06,000 ‫And for this I'm gonna go into the CloudWatch console. 3 00:00:06,000 --> 00:00:07,920 ‫And it turns out that the X-Ray console 4 00:00:07,920 --> 00:00:10,206 ‫is now in the CloudWatch console. 5 00:00:10,206 --> 00:00:12,300 ‫So you can see it on the left hand side under service map. 6 00:00:12,300 --> 00:00:14,520 ‫Currently we see nothing, but we'll see something soon. 7 00:00:14,520 --> 00:00:17,700 ‫That's because it's better to have X-Ray with the metrics 8 00:00:17,700 --> 00:00:20,730 ‫your logs and your alarms all in one place. 9 00:00:20,730 --> 00:00:23,340 ‫Okay, so if we wanted to have some data in X-Ray 10 00:00:23,340 --> 00:00:24,870 ‫we need to set up a demo app 11 00:00:24,870 --> 00:00:27,510 ‫but it turns out that, well, the demo app 12 00:00:27,510 --> 00:00:30,840 ‫as per my trials and errors, doesn't work in AWS. 13 00:00:30,840 --> 00:00:33,450 ‫So therefore I've created my own demo app 14 00:00:33,450 --> 00:00:36,330 ‫that is a modification of what AWS has created. 15 00:00:36,330 --> 00:00:39,540 ‫And we'll deploy this on CloudFormation. 16 00:00:39,540 --> 00:00:42,300 ‫So you go to CloudFormation and you create a stack. 17 00:00:42,300 --> 00:00:44,460 ‫And the stack we're going to use in here 18 00:00:44,460 --> 00:00:47,010 ‫is the stack that's under the X-Ray folder 19 00:00:47,010 --> 00:00:49,830 ‫called EB Javas Scorekeep X-Ray simplified. 20 00:00:49,830 --> 00:00:53,137 ‫This is a simplified template from AWS. 21 00:00:54,155 --> 00:00:56,130 ‫So we're going to upload a template file 22 00:00:56,130 --> 00:00:59,430 ‫and choose the EB Javas Scorekeep X-Ray simplified. 23 00:00:59,430 --> 00:01:03,390 ‫So the stack name is going to be called Scorekeep X-Ray. 24 00:01:03,390 --> 00:01:06,060 ‫And then you scroll down, you leave everything as default 25 00:01:06,060 --> 00:01:08,490 ‫except at the very bottom three things. 26 00:01:08,490 --> 00:01:11,640 ‫So for subnet one, you're going to choose the first subnet. 27 00:01:11,640 --> 00:01:14,460 ‫For subnet ID two, you choose the second subnet. 28 00:01:14,460 --> 00:01:19,410 ‫And finally, for VPCID, you choose the VPC right here. 29 00:01:19,410 --> 00:01:20,340 ‫And the reason we do so 30 00:01:20,340 --> 00:01:22,200 ‫is that this is we indicate to the templates 31 00:01:22,200 --> 00:01:25,650 ‫where we want to deploy our resources. 32 00:01:25,650 --> 00:01:29,370 ‫So click on next, then click on next 33 00:01:29,370 --> 00:01:33,360 ‫and then acknowledge and submit. 34 00:01:33,360 --> 00:01:34,620 ‫And this is going to create 35 00:01:34,620 --> 00:01:36,510 ‫a CloudFormation template for us. 36 00:01:36,510 --> 00:01:37,920 ‫And if you have a look at it, 37 00:01:37,920 --> 00:01:40,230 ‫this CloudFormation template actually deploys 38 00:01:40,230 --> 00:01:41,970 ‫an ECS cluster. 39 00:01:41,970 --> 00:01:44,700 ‫And then we're going to have a front-end API 40 00:01:44,700 --> 00:01:47,610 ‫a front-end image, sorry, a backend API 41 00:01:47,610 --> 00:01:51,720 ‫all using X-Ray so that we see data in the X-Ray folder 42 00:01:51,720 --> 00:01:55,500 ‫and then it's going to be running on the T2 or T3 micro. 43 00:01:55,500 --> 00:01:57,150 ‫Okay, so this is good. 44 00:01:57,150 --> 00:02:00,540 ‫Now let's go in here and wait for this to be fully done. 45 00:02:00,540 --> 00:02:02,850 ‫Okay, so my stack is now fully deployed 46 00:02:02,850 --> 00:02:04,140 ‫and if I go into resources 47 00:02:04,140 --> 00:02:06,270 ‫I can see all the things that have been created 48 00:02:06,270 --> 00:02:08,640 ‫as part of this confirmation templates. 49 00:02:08,640 --> 00:02:11,220 ‫So we can see, for example, an ECS execution role 50 00:02:11,220 --> 00:02:14,880 ‫ASG a game table, which is DynamoDB and so on. 51 00:02:14,880 --> 00:02:18,180 ‫So how do we use this web application. 52 00:02:18,180 --> 00:02:20,970 ‫Well, you go to outputs, refresh this 53 00:02:20,970 --> 00:02:23,166 ‫and then we have the loaded balancer. 54 00:02:23,166 --> 00:02:25,590 ‫You are over here that you just open in your new page. 55 00:02:25,590 --> 00:02:28,140 ‫And then you should have this kind of UI. 56 00:02:28,140 --> 00:02:30,900 ‫So I'm going to leave the session as games. 57 00:02:30,900 --> 00:02:34,320 ‫I'm going to leave this to random and click on create. 58 00:02:34,320 --> 00:02:35,760 ‫Here we have to create a game name. 59 00:02:35,760 --> 00:02:38,340 ‫So I'm going to create a Sample Game 60 00:02:38,340 --> 00:02:40,950 ‫and then the rules of it is going to be Tic Tac Toe. 61 00:02:40,950 --> 00:02:42,570 ‫And then click on create. 62 00:02:42,570 --> 00:02:44,970 ‫And now we can view the traces recession 63 00:02:44,970 --> 00:02:46,650 ‫but you click on this. 64 00:02:46,650 --> 00:02:49,440 ‫This is going to take you to the old X-Ray console, 65 00:02:49,440 --> 00:02:50,610 ‫which is right here. 66 00:02:50,610 --> 00:02:52,500 ‫And as you can see there's a new X-Ray console, 67 00:02:52,500 --> 00:02:53,730 ‫experience available. 68 00:02:53,730 --> 00:02:56,370 ‫That is the one that I'm showing you right here. 69 00:02:56,370 --> 00:02:58,830 ‫So for now, let's just keep on playing. 70 00:02:58,830 --> 00:03:01,770 ‫So let's click on this game and click on play. 71 00:03:01,770 --> 00:03:03,840 ‫And here we have a classic game of Tic Tac Toe. 72 00:03:03,840 --> 00:03:06,240 ‫So you just click wherever you want. 73 00:03:06,240 --> 00:03:07,950 ‫So here, here, here. 74 00:03:07,950 --> 00:03:09,510 ‫And then, oh, you see there's a line. 75 00:03:09,510 --> 00:03:13,590 ‫So you'll see in a second that X has won, so X wins. 76 00:03:13,590 --> 00:03:17,730 ‫So yes, we have done this entire game 77 00:03:17,730 --> 00:03:19,980 ‫and we could go back and play more games. 78 00:03:19,980 --> 00:03:22,410 ‫What's going to happen is that as we play the games 79 00:03:22,410 --> 00:03:25,740 ‫this is going to send traces into X-Ray. 80 00:03:25,740 --> 00:03:27,960 ‫And so if I go into X-Ray right here 81 00:03:27,960 --> 00:03:30,420 ‫and look at my service map, which is the first part. 82 00:03:30,420 --> 00:03:31,830 ‫So I'm going to zoom out a little bit 83 00:03:31,830 --> 00:03:33,180 ‫just for this ones. 84 00:03:33,180 --> 00:03:34,680 ‫So this is my service map, 85 00:03:34,680 --> 00:03:38,850 ‫and this shows the dependencies of all my components in AWS 86 00:03:38,850 --> 00:03:41,160 ‫and how they relate towards the API calls 87 00:03:41,160 --> 00:03:42,160 ‫that have been made. 88 00:03:43,140 --> 00:03:46,680 ‫And as you can see, we have an ECS container right here. 89 00:03:46,680 --> 00:03:48,600 ‫This is what's representing it. 90 00:03:48,600 --> 00:03:52,530 ‫And then we also have a DynamoDB table. 91 00:03:52,530 --> 00:03:53,970 ‫We have another DynamoDB table. 92 00:03:53,970 --> 00:03:55,380 ‫So we have two of them. 93 00:03:55,380 --> 00:03:56,213 ‫We have an SNS. 94 00:03:56,213 --> 00:03:59,190 ‫And you see right now it's a bit orange 95 00:03:59,190 --> 00:04:02,340 ‫is because this is an error and we'll have a look at it. 96 00:04:02,340 --> 00:04:03,660 ‫We also have a session table 97 00:04:03,660 --> 00:04:07,560 ‫we have a state table, an SNS topic, and another table. 98 00:04:07,560 --> 00:04:10,110 ‫So we have so many DynamoDB tables and so on. 99 00:04:10,110 --> 00:04:11,490 ‫And this is the service map. 100 00:04:11,490 --> 00:04:13,940 ‫So you can imagine as you have many microservices 101 00:04:14,790 --> 00:04:17,400 ‫and all of them making API calls to each other 102 00:04:17,400 --> 00:04:19,800 ‫if they're all instrumented with X-Ray 103 00:04:19,800 --> 00:04:21,780 ‫then you will start seeing the dependencies 104 00:04:21,780 --> 00:04:23,460 ‫between all these services. 105 00:04:23,460 --> 00:04:25,380 ‫And on top of it, in case there is an error 106 00:04:25,380 --> 00:04:27,497 ‫this will be highlighted right here. 107 00:04:27,497 --> 00:04:29,280 ‫So if we click on this, for example 108 00:04:29,280 --> 00:04:31,290 ‫we can have a look at the latency. 109 00:04:31,290 --> 00:04:34,440 ‫So we see the average latency and so on over time 110 00:04:34,440 --> 00:04:36,900 ‫the number of requests over time, number of faults 111 00:04:36,900 --> 00:04:39,810 ‫and the response time distribution if we want it to. 112 00:04:39,810 --> 00:04:43,030 ‫And as we have a look at this, if I click on here 113 00:04:44,130 --> 00:04:47,550 ‫as you can see here, it says error 100% to SNS. 114 00:04:47,550 --> 00:04:50,760 ‫So it looks like that SNS is getting some errors. 115 00:04:50,760 --> 00:04:53,310 ‫And so what I can do is that I can analyze these traces 116 00:04:53,310 --> 00:04:55,143 ‫by clicking on view traces. 117 00:04:56,010 --> 00:05:00,360 ‫So now we have these, this is the traces console 118 00:05:00,360 --> 00:05:03,030 ‫and this is where we can start to query some traces 119 00:05:03,030 --> 00:05:06,379 ‫so we can run a query and view what's happening. 120 00:05:06,379 --> 00:05:07,860 ‫But currently we don't have any data. 121 00:05:07,860 --> 00:05:10,950 ‫So instead I'm going to do is just run a query with nothing. 122 00:05:10,950 --> 00:05:14,700 ‫And as you can see, we have 21 different traces. 123 00:05:14,700 --> 00:05:16,410 ‫So everything looks good. 124 00:05:16,410 --> 00:05:18,390 ‫And what's going to happen 125 00:05:18,390 --> 00:05:20,100 ‫is that you can filter them by note. 126 00:05:20,100 --> 00:05:21,960 ‫So figure out which ones are going to be important to you. 127 00:05:21,960 --> 00:05:23,850 ‫So maybe you just wanna look at traces 128 00:05:23,850 --> 00:05:25,650 ‫related to the ECS container 129 00:05:25,650 --> 00:05:28,284 ‫or to this score, keep game table and so on. 130 00:05:28,284 --> 00:05:30,210 ‫So you can start to build your query. 131 00:05:30,210 --> 00:05:33,570 ‫As you can see, if I only want to look at score keep game 132 00:05:33,570 --> 00:05:34,920 ‫then I can add to query. 133 00:05:34,920 --> 00:05:38,580 ‫And this is going to populate my trace query right here. 134 00:05:38,580 --> 00:05:42,270 ‫And I can run my query and instead of 21, I have 10 traces. 135 00:05:42,270 --> 00:05:44,670 ‫And then on top of it, now half this, 136 00:05:44,670 --> 00:05:47,850 ‫I can look at like the response graphs in terms of latency. 137 00:05:47,850 --> 00:05:49,470 ‫So it looks like most of my requests 138 00:05:49,470 --> 00:05:51,720 ‫are under 200 milliseconds 139 00:05:51,720 --> 00:05:56,130 ‫but there has been one request at over 500 milliseconds. 140 00:05:56,130 --> 00:05:57,810 ‫So again, it really depends on 141 00:05:57,810 --> 00:05:58,890 ‫what you want to get out of it 142 00:05:58,890 --> 00:06:00,540 ‫but this could be some good indications 143 00:06:00,540 --> 00:06:01,950 ‫and help you look into, for example 144 00:06:01,950 --> 00:06:04,980 ‫this one request right here that was slow. 145 00:06:04,980 --> 00:06:07,050 ‫And we can have a look and understand. 146 00:06:07,050 --> 00:06:11,490 ‫So if we look at the duration, this is probably this one. 147 00:06:11,490 --> 00:06:12,690 ‫So if you click on it now 148 00:06:12,690 --> 00:06:15,270 ‫you have details about a specific trace. 149 00:06:15,270 --> 00:06:17,550 ‫And so this trace is going to show you 150 00:06:17,550 --> 00:06:19,710 ‫the trace map just for that once. 151 00:06:19,710 --> 00:06:20,820 ‫So as you can see, we have 152 00:06:20,820 --> 00:06:22,560 ‫a little bit less information in here 153 00:06:22,560 --> 00:06:26,130 ‫because this trace was using only the ECS container 154 00:06:26,130 --> 00:06:29,250 ‫and four DynamoDB tables. 155 00:06:29,250 --> 00:06:31,800 ‫And if you scroll down now 156 00:06:31,800 --> 00:06:35,400 ‫you see the actual breakdown of the request 157 00:06:35,400 --> 00:06:37,680 ‫based on the different events that happens. 158 00:06:37,680 --> 00:06:38,513 ‫And so you can see 159 00:06:38,513 --> 00:06:41,130 ‫that this post right here to this URL 160 00:06:41,130 --> 00:06:44,910 ‫actually triggered a lot of API calls to DynamoDB. 161 00:06:44,910 --> 00:06:47,430 ‫So first get item on score, keep game 162 00:06:47,430 --> 00:06:50,430 ‫then get item on score clip states and so on. 163 00:06:50,430 --> 00:06:53,910 ‫And you can see the latency, how long each take and so on. 164 00:06:53,910 --> 00:06:56,910 ‫So this gives you some information around your data. 165 00:06:56,910 --> 00:06:58,980 ‫And of course as you click on it, 166 00:06:58,980 --> 00:07:01,800 ‫then you're going to get some segment details information 167 00:07:01,800 --> 00:07:03,600 ‫to look whether or not you had errors, 168 00:07:03,600 --> 00:07:06,270 ‫to look the resources, the annotations, if anything, 169 00:07:06,270 --> 00:07:07,103 ‫and the metadata. 170 00:07:07,103 --> 00:07:08,850 ‫So you can get a lot of information 171 00:07:08,850 --> 00:07:10,980 ‫around what failed and what didn't fail. 172 00:07:10,980 --> 00:07:13,170 ‫And of course, this is only relevant 173 00:07:13,170 --> 00:07:15,690 ‫when there is a failure for analyzing the failures 174 00:07:15,690 --> 00:07:18,600 ‫but this gives you really good latency information. 175 00:07:18,600 --> 00:07:20,520 ‫And if you had CloudHSM logs enabled 176 00:07:20,520 --> 00:07:23,010 ‫then you could also see the corresponding logs 177 00:07:23,010 --> 00:07:24,090 ‫for that specific trace 178 00:07:24,090 --> 00:07:27,390 ‫which makes X-Ray really, really, really powerful. 179 00:07:27,390 --> 00:07:28,290 ‫So that's it. 180 00:07:28,290 --> 00:07:30,600 ‫That's what I want you to remember for X-Ray. 181 00:07:30,600 --> 00:07:31,980 ‫Now in the state of things, 182 00:07:31,980 --> 00:07:34,560 ‫right now X-Ray does not have all the features 183 00:07:34,560 --> 00:07:35,520 ‫from the previous console 184 00:07:35,520 --> 00:07:38,460 ‫so we only have service map and traces. 185 00:07:38,460 --> 00:07:41,501 ‫But if you're go in here in the X-Ray console 186 00:07:41,501 --> 00:07:44,160 ‫as you can see, we have configurations 187 00:07:44,160 --> 00:07:46,530 ‫such as sampling, encryption, and groups 188 00:07:46,530 --> 00:07:49,380 ‫which are don't appear yet in this console. 189 00:07:49,380 --> 00:07:52,290 ‫So for now I may use this console 190 00:07:52,290 --> 00:07:53,969 ‫as well in the future videos. 191 00:07:53,969 --> 00:07:57,090 ‫Just know that X-Ray and you're good to go. 192 00:07:57,090 --> 00:08:00,150 ‫And finally, just to be clear, 193 00:08:00,150 --> 00:08:01,740 ‫you need to delete the stack 194 00:08:01,740 --> 00:08:03,510 ‫so that it doesn't leave it running. 195 00:08:03,510 --> 00:08:06,540 ‫So you can just delete it, call the score, keep X-Ray 196 00:08:06,540 --> 00:08:09,150 ‫delete the stack, and you're good to go. 197 00:08:09,150 --> 00:08:10,500 ‫All right, that's it for this lecture. 198 00:08:10,500 --> 00:08:13,500 ‫I hope you liked it, and I will see you in the next lecture.