|
19 | 19 | "metadata": {},
|
20 | 20 | "source": [
|
21 | 21 | "## Setup\n",
|
22 |
| - "This notebook was tested on **AI Platform Notebooks** using the standard TF 2.2 image." |
| 22 | + "This notebook was tested on **AI Platform Notebooks** using the standard TF 2.8 image." |
23 | 23 | ]
|
24 | 24 | },
|
25 | 25 | {
|
26 | 26 | "cell_type": "markdown",
|
27 | 27 | "metadata": {},
|
28 | 28 | "source": [
|
29 |
| - "### Install required packages" |
| 29 | + "### Install required packages\n", |
| 30 | + "\n", |
| 31 | + "You can safely ignore the dependency errors. Confirm the last message starting from \"Successfully installed...\"" |
30 | 32 | ]
|
31 | 33 | },
|
32 | 34 | {
|
|
35 | 37 | "metadata": {},
|
36 | 38 | "outputs": [],
|
37 | 39 | "source": [
|
38 |
| - "%pip install -q -U locust google-cloud-monitoring google-cloud-logging google-cloud-monitoring-dashboards" |
| 40 | + "!pip install --user locust==2.11.1\\\n", |
| 41 | + " google-cloud-monitoring==2.11.1\\\n", |
| 42 | + " google-cloud-logging==3.2.2\\\n", |
| 43 | + " google-cloud-monitoring-dashboards==2.7.2" |
39 | 44 | ]
|
40 | 45 | },
|
41 | 46 | {
|
|
80 | 85 | "from google.api_core.exceptions import GoogleAPICallError \n",
|
81 | 86 | "\n",
|
82 | 87 | "from google.cloud import logging_v2\n",
|
83 |
| - "from google.cloud.logging_v2 import MetricsServiceV2Client\n", |
84 |
| - "from google.cloud.logging_v2 import LoggingServiceV2Client\n", |
| 88 | + "from google.cloud.logging_v2.services.metrics_service_v2 import MetricsServiceV2Client\n", |
| 89 | + "from google.cloud.logging_v2.services.logging_service_v2 import LoggingServiceV2Client\n", |
85 | 90 | "\n",
|
86 |
| - "from google.cloud.monitoring_dashboard.v1.types import Dashboard\n", |
87 |
| - "from google.cloud.monitoring_dashboard.v1 import DashboardsServiceClient\n", |
| 91 | + "from google.cloud.monitoring_dashboard_v1.types import Dashboard\n", |
| 92 | + "from google.cloud.monitoring_dashboard_v1 import DashboardsServiceClient\n", |
88 | 93 | "from google.cloud.monitoring_v3 import MetricServiceClient\n",
|
89 | 94 | "from google.cloud.monitoring_v3.query import Query\n",
|
90 | 95 | "from google.cloud.monitoring_v3.types import TimeInterval\n",
|
|
160 | 165 | " value_field:str, \n",
|
161 | 166 | " bucket_bounds:List[int]):\n",
|
162 | 167 | " \n",
|
163 |
| - " metric_path = logging_client.metric_path(PROJECT_ID, metric_name)\n", |
| 168 | + " metric_path = logging_client.log_metric_path(PROJECT_ID, metric_name)\n", |
164 | 169 | " log_entry_filter = 'resource.type=global AND logName={}'.format(log_path)\n",
|
165 | 170 | " \n",
|
166 | 171 | " metric_descriptor = {\n",
|
|
203 | 208 | " logging_client.get_log_metric(metric_path)\n",
|
204 | 209 | " print('Metric: {} already exists'.format(metric_path))\n",
|
205 | 210 | " except:\n",
|
206 |
| - " logging_client.create_log_metric(parent, metric)\n", |
| 211 | + " request = logging_v2.types.logging_metrics.CreateLogMetricRequest(\n", |
| 212 | + " parent=parent,\n", |
| 213 | + " metric=metric,\n", |
| 214 | + " )\n", |
| 215 | + " logging_client.create_log_metric(request)\n", |
207 | 216 | " print('Created metric {}'.format(metric_path))"
|
208 | 217 | ]
|
209 | 218 | },
|
|
225 | 234 | "creds , _ = google.auth.default()\n",
|
226 | 235 | "logging_client = MetricsServiceV2Client(credentials=creds)\n",
|
227 | 236 | "\n",
|
228 |
| - "parent = logging_client.project_path(PROJECT_ID)\n", |
| 237 | + "parent = logging_client.common_project_path(PROJECT_ID)\n", |
229 | 238 | "log_path = LoggingServiceV2Client.log_path(PROJECT_ID, log_name)"
|
230 | 239 | ]
|
231 | 240 | },
|
|
284 | 293 | "metadata": {},
|
285 | 294 | "outputs": [],
|
286 | 295 | "source": [
|
287 |
| - "metrics = logging_client.list_log_metrics(parent)\n", |
| 296 | + "request = {'parent': parent}\n", |
| 297 | + "metrics = logging_client.list_log_metrics(request)\n", |
288 | 298 | "\n",
|
289 | 299 | "if not list(metrics):\n",
|
290 | 300 | " print(\"There are not any log based metrics defined in the the project\")\n",
|
291 | 301 | "else:\n",
|
292 |
| - " for element in logging_client.list_log_metrics(parent):\n", |
| 302 | + " for element in logging_client.list_log_metrics(request):\n", |
293 | 303 | " print(element.metric_descriptor.name)"
|
294 | 304 | ]
|
295 | 305 | },
|
|
337 | 347 | "outputs": [],
|
338 | 348 | "source": [
|
339 | 349 | "dashboard_proto = Dashboard()\n",
|
340 |
| - "dashboard_proto = ParseDict(dashboard_template, dashboard_proto)\n", |
341 |
| - "dashboard = dashboard_service_client.create_dashboard(parent, dashboard_proto)" |
| 350 | + "request = {\n", |
| 351 | + " 'parent': parent,\n", |
| 352 | + " 'dashboard': dashboard_proto,\n", |
| 353 | + "}\n", |
| 354 | + "dashboard_proto = ParseDict(dashboard_template, dashboard_proto._pb)\n", |
| 355 | + "dashboard = dashboard_service_client.create_dashboard(request)" |
342 | 356 | ]
|
343 | 357 | },
|
344 | 358 | {
|
|
347 | 361 | "metadata": {},
|
348 | 362 | "outputs": [],
|
349 | 363 | "source": [
|
350 |
| - "for dashboard in dashboard_service_client.list_dashboards(parent):\n", |
| 364 | + "for dashboard in dashboard_service_client.list_dashboards({'parent': parent}):\n", |
351 | 365 | " print('Dashboard name: {}, Dashboard ID: {}'.format(dashboard.display_name, dashboard.name))"
|
352 | 366 | ]
|
353 | 367 | },
|
|
357 | 371 | "source": [
|
358 | 372 | "## 3. Deploying Locust to a GKE cluster\n",
|
359 | 373 | "\n",
|
360 |
| - "Before proceeding, you need access to a GKE cluster. The described deployment process can deploy Locust to any GKE cluster as long as there are enough compute resources to support your Locust configuration. The default configuration follows the Locust's best practices and requests one processor core and 4Gi of memory for the Locust master and one processor core and 2Gi of memory for each Locust worker. As you run your tests, it is important to monitor the the master and the workers for resource utilization and fine tune the allocated resources as required.\n", |
| 374 | + "Before proceeding, you need access to a GKE cluster. You can find a command to create a GKE cluster in [Environment setup](https://github.com/GoogleCloudPlatform/mlops-on-gcp/blob/master/model_serving/caip-load-testing/README.md#environment-setup) section of [README.md](https://github.com/GoogleCloudPlatform/mlops-on-gcp/blob/master/model_serving/caip-load-testing/README.md). The described deployment process can deploy Locust to any GKE cluster as long as there are enough compute resources to support your Locust configuration. The default configuration follows the Locust's best practices and requests one processor core and 4Gi of memory for the Locust master and one processor core and 2Gi of memory for each Locust worker. As you run your tests, it is important to monitor the the master and the workers for resource utilization and fine tune the allocated resources as required.\n", |
361 | 375 | "\n",
|
362 | 376 | "The deployment process has been streamlined using [Kustomize](https://kustomize.io/). As described in the following steps, you can fine tune the baseline configuration by modifying the default `kustomization.yaml` and `patch.yaml` files in the `locust/manifests` folder.\n",
|
363 | 377 | "\n"
|
|
623 | 637 | "source": [
|
624 | 638 | "You can try using the following parameter configurations:\n",
|
625 | 639 | "1. Number of total users to simulate: 152\n",
|
626 |
| - "2. Hatch rate: 1\n", |
627 |
| - "3. Host: http://ml.googleapis.com\n", |
628 |
| - "4. Number of users to increase by step: 8\n", |
629 |
| - "5. Step duration: 1m " |
| 640 | + "2. Spawn rate: 1\n", |
| 641 | + "3. Host: `http://[your-region]-ml.googleapis.com`\n", |
| 642 | + "\n", |
| 643 | + "**NOTE**: `[your-region]` is the region for deploying the model that you configured as `REGION` in the first notebook. " |
630 | 644 | ]
|
631 | 645 | },
|
632 | 646 | {
|
|
0 commit comments