Skip to content

Commit

Permalink
fix return code for multi-app run k8s
Browse files Browse the repository at this point in the history
Signed-off-by: Mukundan Sundararajan <[email protected]>
  • Loading branch information
mukundansundar committed Sep 22, 2023
1 parent b219170 commit 5a85a55
Showing 1 changed file with 4 additions and 188 deletions.
192 changes: 4 additions & 188 deletions tutorials/hello-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,191 +191,6 @@ curl --request POST --data "@sample.json" --header Content-Type:application/json
Expected output:
Empty reply from server

Confirm the order was persisted by requesting it from the app

<!-- STEP
name: order Test
expected_stdout_lines:
- '{"orderId":"42"}'
-->

```bash
curl http://localhost:8080/order
```

Expected output:

```json
{ "orderId": "42" }
```

<!-- END_STEP -->

> **Optional**: Now it would be a good time to get acquainted with the [Dapr dashboard](https://docs.dapr.io/reference/cli/dapr-dashboard/). Which is a convenient interface to check status, information and logs of applications running on Dapr. The following command will make it available on http://localhost:9999/.
```bash
dapr dashboard -k -p 9999
```

### Step 5 - Deploy the Python app with the Dapr sidecar

Next, take a quick look at the Python app. Navigate to the Python app in the kubernetes quickstart: `cd quickstarts/tutorials/hello-kubernetes/python` and open `app.py`.

At a quick glance, this is a basic Python app that posts JSON messages to `localhost:3500`, which is the default listening port for Dapr. You can invoke the Node.js application's `neworder` endpoint by posting to `v1.0/invoke/nodeapp/method/neworder`. The message contains some `data` with an orderId that increments once per second:

```python
n = 0
while True:
n += 1
message = {"data": {"orderId": n}}

try:
response = requests.post(dapr_url, json=message)
except Exception as e:
print(e)

time.sleep(1)
```

<!-- STEP
name: Deploy Python App
sleep: 11
expected_stdout_lines:
- deployment.apps/pythonapp created
- 'deployment "pythonapp" successfully rolled out'
-->

Deploy the Python app to your Kubernetes cluster:

```bash
kubectl apply -f ./deploy/python.yaml
```

As with above, the following command will wait for the deployment to complete:

```bash
kubectl rollout status deploy/pythonapp
```

<!-- END_STEP -->

### Step 6 - Observe messages

Now that the Node.js and Python applications are deployed, watch messages come through:

Get the logs of the Node.js app:

<!-- TODO(artursouza): Add "Successfully persisted state for Order ID: X" once the new image is published -->

<!-- STEP
expected_stdout_lines:
- "Got a new order! Order ID: 11"
- "Successfully persisted state for Order ID: 11"
expected_stderr_lines:
output_match_mode: substring
match_order: none
name: Read nodeapp logs
-->

```bash
kubectl logs --selector=app=node -c node --tail=-1
```

<!-- END_STEP -->

If all went well, you should see logs like this:

```
Got a new order! Order ID: 1
Successfully persisted state for Order ID: 1
Got a new order! Order ID: 2
Successfully persisted state for Order ID: 2
Got a new order! Order ID: 3
Successfully persisted state for Order ID: 3
```

### Step 7 - Observe API call logs

Now that the Node.js and Python applications are deployed, watch API call logs come through:

Get the API call logs of the node app:

<!-- STEP
expected_stdout_lines:
- 'method="POST /v1.0/state/statestore"'
expected_stderr_lines:
output_match_mode: substring
name: Read nodeapp logs
-->

```bash
kubectl logs --selector=app=node -c daprd --tail=-1
```

<!-- END_STEP -->

When save state API calls are made, you should see logs similar to this:

```
time="2022-04-25T22:46:09.82121774Z" level=info method="POST /v1.0/state/statestore" app_id=nodeapp instance=nodeapp-7dd6648dd4-7hpmh scope=dapr.runtime.http-info type=log ver=1.7.2
time="2022-04-25T22:46:10.828764787Z" level=info method="POST /v1.0/state/statestore" app_id=nodeapp instance=nodeapp-7dd6648dd4-7hpmh scope=dapr.runtime.http-info type=log ver=1.7.2
```

Get the API call logs of the Python app:

<!-- STEP
expected_stdout_lines:
- 'method="POST /neworder"'
expected_stderr_lines:
output_match_mode: substring
name: Read pythonapp logs
-->

```bash
kubectl logs --selector=app=python -c daprd --tail=-1
```
<!-- END_STEP -->

```
time="2022-04-27T02:47:49.972688145Z" level=info method="POST /neworder" app_id=pythonapp instance=pythonapp-545df48d55-jvj52 scope=dapr.runtime.http-info type=log ver=1.7.2
time="2022-04-27T02:47:50.984994545Z" level=info method="POST /neworder" app_id=pythonapp instance=pythonapp-545df48d55-jvj52 scope=dapr.runtime.http-info type=log ver=1.7.2
```

### Step 8 - Confirm successful persistence

Call the Node.js app's order endpoint to get the latest order. Grab the external IP address that you saved before and, append "/order" and perform a GET request against it (enter it into your browser, use Postman, or curl it!):

```
curl $NODE_APP/order
{"orderID":"42"}
```

You should see the latest JSON in response!

### Step 9 - Cleanup

Once you're done, you can spin down your Kubernetes resources by navigating to the `./deploy` directory and running:

<!-- STEP
name: "Delete resources from Kubernetes"
working_dir: "./deploy"
sleep: 10
expected_stdout_lines:
- service "nodeapp" deleted
- deployment.apps "nodeapp" deleted
- deployment.apps "pythonapp" deleted
- component.dapr.io "statestore" deleted
output_match_mode: substring
match_order: none
-->

```bash
kubectl delete -f .
```

<!-- END_STEP -->

This will spin down each resource defined by the .yaml files in the `deploy` directory, including the state component.

## Using Dapr Mutli-app run

Expand Down Expand Up @@ -413,20 +228,22 @@ Expected output
To run both the Node.js and Python apps, run the following command from the `hello-kubernetes` directory:
<!-- STEP
name: "Run hello-kubernetes multi-app run tempalte"
sleep: 15
timeout_seconds: 60
timeout_seconds: 30
expected_return_code:
expected_stdout_lines:
- 'Deploying app "nodeapp" to Kubernetes'
- 'Deploying app "pythonapp" to Kubernetes'
- '== APP - nodeapp == Got a new order! Order ID: 12'
- '== APP - nodeapp == Successfully persisted state for Order ID: 12'
expected_stderr_lines:
background: true
output_match_mode: substring
match_order: none
-->
```bash
dapr run -k -f dapr.yaml
```
<!-- END_STEP -->

Expected output
```
Expand Down Expand Up @@ -458,7 +275,6 @@ On pressing `Ctrl+C` the CLI process exits after deleting the Kubernetes resourc
```bash
dapr stop -k -f dapr.yaml
```
<!-- END_STEP -->

## Deploying your code

Expand Down

0 comments on commit 5a85a55

Please sign in to comment.