|
| 1 | +:_mod-docs-content-type: ASSEMBLY |
| 2 | +[id="cloud-experts-deploying-application-logging"] |
| 3 | += Tutorial: Logging |
| 4 | +include::_attributes/common-attributes.adoc[] |
| 5 | +include::_attributes/attributes-openshift-dedicated.adoc[] |
| 6 | +:context: cloud-experts-deploying-application-logging |
| 7 | + |
| 8 | +toc::[] |
| 9 | + |
| 10 | +//rosaworkshop.io content metadata |
| 11 | +//Brought into ROSA product docs 2024-05-01 |
| 12 | + |
| 13 | +There are various methods to view your logs in {product-rosa} (ROSA). Use the following procedures to forward the logs to AWS CloudWatch and view the logs directly through the pod by using `oc logs`. |
| 14 | + |
| 15 | +[NOTE] |
| 16 | +==== |
| 17 | +ROSA is not preconfigured with a logging solution. |
| 18 | +==== |
| 19 | + |
| 20 | +.Prerequisites |
| 21 | + |
| 22 | +* Set up a logging solution before viewing your logs. See the xref:../../observability/logging/cluster-logging-deploying.adoc#cluster-logging-deploying[Installing logging] documentation for more information. |
| 23 | +
|
| 24 | +[role="_additional-resources"] |
| 25 | +.Additional resources |
| 26 | +* xref:../../observability/logging/cluster-logging.adoc#cluster-logging[Cluster logging] |
| 27 | +
|
| 28 | +== Forwarding logs to CloudWatch |
| 29 | + |
| 30 | +Install the logging add-on service to forward the logs to AWS CloudWatch. |
| 31 | + |
| 32 | +//These steps were adopted from the Managed OpenShift Black Belt Tutorial "Using the AWS CloudWatch agent to publish metrics to CloudWatch in ROSA". |
| 33 | + |
| 34 | +. Run the following script to configure your ROSA cluster to forward logs to CloudWatch: |
| 35 | ++ |
| 36 | +[source,terminal] |
| 37 | +---- |
| 38 | +$ curl https://raw.githubusercontent.com/openshift-cs/rosaworkshop/master/rosa-workshop/ostoy/resources/configure-cloudwatch.sh | bash |
| 39 | +---- |
| 40 | ++ |
| 41 | +[NOTE] |
| 42 | +==== |
| 43 | +Configuring ROSA to send logs to CloudWatch goes beyond the scope of this tutorial. Integrating with AWS and enabling CloudWatch logging are important aspects of ROSA, so a script is included to simplify the configuration process. The script will automatically set up AWS CloudWatch. You can examine the script to understand the steps involved. |
| 44 | +==== |
| 45 | ++ |
| 46 | +.Example output |
| 47 | ++ |
| 48 | +[source,terminal] |
| 49 | +---- |
| 50 | +Varaibles are set...ok. |
| 51 | +Policy already exists...ok. |
| 52 | +Created RosaCloudWatch-mycluster role. |
| 53 | +Attached role policy. |
| 54 | +Deploying the Red Hat OpenShift Logging Operator |
| 55 | +namespace/openshift-logging configured |
| 56 | +operatorgroup.operators.coreos.com/cluster-logging created |
| 57 | +subscription.operators.coreos.com/cluster-logging created |
| 58 | +Waiting for Red Hat OpenShift Logging Operator deployment to complete... |
| 59 | +Red Hat OpenShift Logging Operator deployed. |
| 60 | +secret/cloudwatch-credentials created |
| 61 | +clusterlogforwarder.logging.openshift.io/instance created |
| 62 | +clusterlogging.logging.openshift.io/instance created |
| 63 | +Complete. |
| 64 | +---- |
| 65 | +. After a few minutes, you should begin to see log groups inside of AWS CloudWatch. Run the following command to see the log groups: |
| 66 | ++ |
| 67 | +[source,terminal] |
| 68 | +---- |
| 69 | +$ aws logs describe-log-groups --log-group-name-prefix rosa-mycluster |
| 70 | +---- |
| 71 | ++ |
| 72 | +.Example output |
| 73 | ++ |
| 74 | +[source,terminal] |
| 75 | +---- |
| 76 | +{ |
| 77 | + "logGroups": [ |
| 78 | + { |
| 79 | + "logGroupName": "rosa-mycluster.application", |
| 80 | + "creationTime": 1724104537717, |
| 81 | + "metricFilterCount": 0, |
| 82 | + "arn": "arn:aws:logs:us-west-2:000000000000:log-group:rosa-mycluster.application:*", |
| 83 | + "storedBytes": 0, |
| 84 | + "logGroupClass": "STANDARD", |
| 85 | + "logGroupArn": "arn:aws:logs:us-west-2:000000000000:log-group:rosa-mycluster.application" |
| 86 | + }, |
| 87 | + { |
| 88 | + "logGroupName": "rosa-mycluster.audit", |
| 89 | + "creationTime": 1724104152968, |
| 90 | + "metricFilterCount": 0, |
| 91 | + "arn": "arn:aws:logs:us-west-2:000000000000:log-group:rosa-mycluster.audit:*", |
| 92 | + "storedBytes": 0, |
| 93 | + "logGroupClass": "STANDARD", |
| 94 | + "logGroupArn": "arn:aws:logs:us-west-2:000000000000:log-group:rosa-mycluster.audit" |
| 95 | + }, |
| 96 | +---- |
| 97 | + |
| 98 | +== Outputting the data to the streams and logs |
| 99 | +. Output a message to `stdout`. |
| 100 | +.. In the OSToy application, click *Home* and then click the message box for *Log Message (stdout)*. |
| 101 | +.. Write a message to output to the `stdout` stream, for example "All is well!". |
| 102 | +.. Click *Send Message*. |
| 103 | ++ |
| 104 | +image:cloud-experts-deploying-application-logging-ostoy-stdout.png[] |
| 105 | ++ |
| 106 | +. Output a message to `stderr`. |
| 107 | +.. Click the message box for *Log Message (stderr)*. |
| 108 | +.. Write a message to output to the `stderr` stream, for example "Oh no! Error!". |
| 109 | +.. Click *Send Message*. |
| 110 | ++ |
| 111 | +image:cloud-experts-deploying-application-logging-ostoy-stderr.png[] |
| 112 | + |
| 113 | +== Viewing the application logs by using the `oc` command |
| 114 | +. Enter the following command in the command line interface (CLI) to retrieve the name of your frontend pod: |
| 115 | ++ |
| 116 | +[source,terminal] |
| 117 | +---- |
| 118 | +$ oc get pods -o name |
| 119 | +---- |
| 120 | ++ |
| 121 | +.Example output |
| 122 | ++ |
| 123 | +[source,terminal] |
| 124 | +---- |
| 125 | +pod/ostoy-frontend-679cb85695-5cn7x <1> |
| 126 | +pod/ostoy-microservice-86b4c6f559-p594d |
| 127 | +---- |
| 128 | +<1> The pod name is `ostoy-frontend-679cb85695-5cn7x`. |
| 129 | ++ |
| 130 | +. Run the following command to see both the `stdout` and `stderr` messages: |
| 131 | ++ |
| 132 | +[source,terminal] |
| 133 | +---- |
| 134 | +$ oc logs <pod-name> |
| 135 | +---- |
| 136 | ++ |
| 137 | +.Example output |
| 138 | ++ |
| 139 | +[source,terminal] |
| 140 | +---- |
| 141 | +$ oc logs ostoy-frontend-679cb85695-5cn7x |
| 142 | +[...] |
| 143 | +ostoy-frontend-679cb85695-5cn7x: server starting on port 8080 |
| 144 | +Redirecting to /home |
| 145 | +stdout: All is well! |
| 146 | +stderr: Oh no! Error! |
| 147 | +---- |
| 148 | + |
| 149 | +== Viewing the logs with CloudWatch |
| 150 | +. Navigate to *CloudWatch* on the link:https://aws.amazon.com/free/?gclid=EAIaIQobChMIoq2X27fZhgMVaAutBh1Q2w1jEAAYASAAEgL5y_D_BwE&trk=7541ebd3-552d-4f98-9357-b542436aa66c&sc_channel=ps&ef_id=EAIaIQobChMIoq2X27fZhgMVaAutBh1Q2w1jEAAYASAAEgL5y_D_BwE:G:s&s_kwcid=AL!4422!3!651751058796!e!!g!!aws%20console!19852662149!145019243977&all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all[AWS web console]. |
| 151 | +. In the left menu, click *Logs* and then *Log groups* to see the different groups of logs. You should see 3 groups: |
| 152 | + |
| 153 | +** `rosa-<cluster-name>.application` |
| 154 | +** `rosa-<cluster-name>.audit` |
| 155 | +** `rosa-<cluster-name>.infrastructure` |
| 156 | ++ |
| 157 | +image:cloud-experts-deploying-application-logging-cw.png[] |
| 158 | ++ |
| 159 | +. Click `rosa-<cluster-name>.application`. |
| 160 | +. Click the log stream for the frontend pod. |
| 161 | ++ |
| 162 | +image:cloud-experts-deploying-application-logging-logstream2.png[] |
| 163 | ++ |
| 164 | +. Filter for `stdout` and `stderr`. |
| 165 | +. Expand the row to show the messages you entered earlier and other pertinent information. |
| 166 | ++ |
| 167 | +image:cloud-experts-deploying-application-logging-stderr.png[] |
| 168 | ++ |
| 169 | +. Return to the log streams and select the microservice. |
| 170 | +. Enter "microservice" in the search bar to see other messages in your logs. |
| 171 | +. Expand one of the entries to see the color the frontend pod received from microservice and which pod sent that color to the frontend pod. |
| 172 | ++ |
| 173 | +image:cloud-experts-deploying-application-logging-messages.png[] |
| 174 | + |
| 175 | +[role="_additional-resources"] |
| 176 | +.Additional resources |
| 177 | +* link:https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html[What is Amazon CloudWatch] |
0 commit comments