Skip to content

Commit 073b77f

Browse files
committed
Add log helper script
1 parent d505fb4 commit 073b77f

2 files changed

Lines changed: 80 additions & 7 deletions

File tree

serverless-fleets/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ A fleet consists of a collection of worker nodes that automatically scale up or
4646
Like applications, jobs, and functions, fleets run within a Code Engine project. A project is a grouping of Code Engine resources within a specific IBM Cloud region. Projects are used to organize resources and manage access to entities such as configmaps, secrets, and persistent data stores.
4747

4848

49-
## Architecture
49+
## Architecture
5050

5151
The architecture used in this tutorial looks as follows.
5252

@@ -75,7 +75,7 @@ The tutorial has been tested on a MacOS and Ubuntu24 client machine with the fol
7575

7676
Clone this repository
7777
```
78-
git clone https://github.com/IBM/CodeEngine.git
78+
git clone https://github.com/IBM/CodeEngine.git
7979
```
8080

8181
Switch to the `serverless-fleets` directory, which will be the root directory for all steps of this tutorial
@@ -295,7 +295,7 @@ Run a serverless fleet to process 100 tasks where each tasks gets 1 CPU and 2 GB
295295
</details>
296296
<br>
297297

298-
In the fleet details you will see 5 workers being provisined. The number of workers is determined by the profile, cpu/memory and number of parallel tasks.
298+
In the fleet details you will see 5 workers being provisined. The number of workers is determined by the profile, cpu/memory and number of parallel tasks.
299299

300300
```
301301
ibmcloud ce fleet get --id <id>
@@ -413,7 +413,7 @@ The 6 tasks are submitted using the `tasks-from-local-file` option using the [wo
413413

414414
![](./images/example_wordcount.png)
415415

416-
The example mounts the [Persistant Data Stores](https://cloud.ibm.com/docs/codeengine?topic=codeengine-persistent-data-store) (PDS) to the container using the `--mount-data-store MOUNT_DIRECTORY=STORAGE_NAME:[SUBPATH]`, where
416+
The example mounts the [Persistant Data Stores](https://cloud.ibm.com/docs/codeengine?topic=codeengine-persistent-data-store) (PDS) to the container using the `--mount-data-store MOUNT_DIRECTORY=STORAGE_NAME:[SUBPATH]`, where
417417
- `MOUNT_DIRECTORY` - is the directory within the container
418418
- `STORAGE_NAME` - is the name of the PDS
419419
- `SUBPATH` - is the prefix within the COS bucket to mount.
@@ -434,10 +434,10 @@ Upload the .txt files from the local data directory to Cloud Object Storage
434434

435435
#### Step 2 - Run the fleet
436436

437-
Launch the fleet to perform `wc` on each of the novels which defines the tasks from [wordcount_commands.jsonl](./wordcount_commands.jsonl) and mounts the input and output data stores.
437+
Launch the fleet to perform `wc` on each of the novels which defines the tasks from [wordcount_commands.jsonl](./wordcount_commands.jsonl) and mounts the input and output data stores.
438438
```
439439
./run_wordcount
440-
```
440+
```
441441

442442
Confirm that you uploaded the files with `#? 1`
443443

@@ -506,7 +506,7 @@ Download the results from the output COS bucket to `./data/output`
506506

507507
```
508508
./download
509-
````
509+
````
510510
511511
512512
🚀 The example was successful, if you can tell the number of words of the "Alice in Wonderland" novel 🚀
@@ -555,6 +555,16 @@ An IBM Cloud Logs instance is being setup and enabled by default during the auto
555555
556556
![](./images/prototype_logs.png)
557557
558+
![](./images/prototype_logs.png)
559+
560+
#### Using helper scripts
561+
562+
If you want to quickly iterate you may use the helper script `fleet-logs` in order to display fleet logs directly in your terminal. The scripts uses a `LOGS_URL` env variable targetting your ICL endpoint, or if unset will try to find that ICL endpoint of your ICL instance. Additionally, you may specify `--fleet-id <fleet-id>`, `--since <duration>`, `--tier <search-tier>` and `--output <output-format>` to parameterize your query. Available values are directly taken from `ibmcloud logs query --help`.
563+
564+
```
565+
./fleet-logs --fleet-id <fleet-id>
566+
```
567+
558568
### Cleanup the Environment
559569
560570
To clean up all IBM Cloud resources, that have been created as part of the provided script, run:

serverless-fleets/fleet_logs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
ICL_ENDPOINT="${LOGS_URL}"
5+
REGION="${REGION:=eu-de}"
6+
NAME_PREFIX="${NAME_PREFIX:=ce-fleet-sandbox}"
7+
RESOURCE_GROUP="${NAME_PREFIX}--rg"
8+
ICL_NAME="${NAME_PREFIX}--icl"
9+
FLEET_ID=
10+
TIER="frequent_search"
11+
OUTPUT="logs-raw"
12+
SINCE="6h0m0s"
13+
14+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
15+
source ${SCRIPT_DIR}/common.sh
16+
17+
target_region $REGION > /dev/null
18+
target_resource_group $RESOURCE_GROUP > /dev/null
19+
20+
ibmcloud plugin show logs > /dev/null
21+
22+
if [[ $? -ne 0 ]]; then
23+
ibmcloud plugin install logs
24+
fi
25+
26+
if [[ -z "${ICL_ENDPOINT}" ]]; then
27+
ICL_ENDPOINT="$(ibmcloud resource service-instance ${ICL_NAME} -o json | jq -r '.[].extensions.external_api')"
28+
fi
29+
30+
while [[ $# -gt 0 ]]; do
31+
case "$1" in
32+
--fleet-id)
33+
shift
34+
FLEET_ID="$1"
35+
;;
36+
37+
--tier)
38+
shift
39+
TIER="$1"
40+
;;
41+
42+
--output)
43+
shift
44+
OUTPUT="$1"
45+
;;
46+
47+
--since)
48+
shift
49+
SINCE="$1"
50+
;;
51+
52+
*)
53+
echo "Unknown flag $1"
54+
exit 1
55+
;;
56+
esac
57+
shift
58+
done
59+
if [ -z "$FLEET_ID" ]; then
60+
ibmcloud logs query --since ${SINCE} --tier ${TIER} --query "source logs | sort by \$m.timestamp" --service-url "${ICL_ENDPOINT}" --output ${OUTPUT}
61+
else
62+
ibmcloud logs query --since ${SINCE} --tier ${TIER} --query "filter \$d.codeengine.fleetId ~ '${FLEET_ID}' | sort by \$m.timestamp" --service-url "${ICL_ENDPOINT}" --output ${OUTPUT}
63+
fi

0 commit comments

Comments
 (0)