Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log forwarding Pebble layer to sparkd #114

Merged
merged 6 commits into from
Oct 29, 2024

Conversation

rgildein
Copy link
Contributor

@rgildein rgildein commented Oct 14, 2024

Add log forwarding layer yaml file, which is used in sparkd.sh and it
use environment variables to configure it.
The env used are:

  • LOKI_URL - url, which can be either Loki itself or Grafana-agent
  • FLAVOUR - executor | driver to distinguish between the executor and the driver
  • SPARK_APPLICATION_ID - spark application id
  • SPARK_USER - user running these Pods / Jobs
  • HOSTNAME - Pod name / hostname

Add integration tests.

How I tested it:

$ rockcraft pack
charmed-spark_3.4.2_amd64.rock 
$ rockcraft.skopeo --insecure-policy copy oci-archive:charmed-spark_3.4.2_amd64.rock docker-daemon:my-charmed-spark:3.4.2 --dest-tls-verify=false
Getting image source signatures
Copying blob 6414378b6477 done   | 
Copying blob b2aef2bd7872 done   | 
Copying blob b73c860d028d done   | 
Copying blob 786708121d29 done   | 
Copying blob 96a2d5fe6170 done   | 
Copying config 4ea9dc90c4 done   | 
Writing manifest to image destination 
$ docker images
REPOSITORY         TAG       IMAGE ID       CREATED       SIZE
<none>             <none>    d932ff815a6c   4 hours ago   1.21GB
<none>             <none>    cc4074381dc8   4 weeks ago   1.21GB
my-charmed-spark   3.4.2     4ea9dc90c4d4   4 weeks ago   1.21GB
$ docker build -t my-charmed-spark:3.4.2 --build-arg BASE_IMAGE="my-charmed-spark:3.4.2" .
[+] Building 0.1s (5/5) FINISHED                                                    docker:default
 => [internal] load build definition from Dockerfile                                          0.0s
 => => transferring dockerfile: 209B                                                          0.0s
 => [internal] load .dockerignore                                                             0.0s
 => => transferring context: 2B                                                               0.0s
 => [internal] load metadata for docker.io/library/my-charmed-spark:3.4.2                     0.0s
 => [1/1] FROM docker.io/library/my-charmed-spark:3.4.2                                       0.0s
 => exporting to image                                                                        0.0s
 => => exporting layers                                                                       0.0s
 => => writing image sha256:43967a182b5d1db6c347972fece1d8db876b1b2d79344ed1ee680875b433d616  0.0s
 => => naming to docker.io/library/my-charmed-spark:3.4.2                                     0.0s
$ docker save my-charmed-spark:3.4.2 -o my-charmed-spark.img
$ microk8s ctr images import --base-name ghcr.io/canonical/my-charmed-spark my-charmed-spark.img
unpacking docker.io/library/my-charmed-spark:3.4.2 (sha256:0cbcb7a400d59e48928983ddf659b576f61a3903c9d900e4752d43b12ae3c2f6)...done

$ cat spark-defaults.conf 
spark.kubernetes.container.image=docker.io/library/my-charmed-spark:3.4.2 
# using grafana-agent-k8s deployed only for this purpose
$ spark-client.pyspark --username spark --namespace spark --properties-file ./spark-defaults.conf -v --conf spark.executorEnv.LOKI_URL=http://grafana-agent-k8s-0.grafana-agent-k8s-endpoints.spark-o11y.svc.cluster.local:3500/loki/api/v1/push
# followed example from https://canonical.com/data/docs/spark/k8s/t-spark-shell to see some logs
...
>>> spark.sparkContext.parallelize(lines.splitlines(), 2).map(count_vowels).reduce(add)

$ k -n spark get pods
NAME                                   READY   STATUS    RESTARTS   AGE
pysparkshell-fb00bc9289e61c8a-exec-1   1/1     Running   0          2s
pysparkshell-fb00bc9289e61c8a-exec-2   1/1     Running   0          2s
$ k -n spark logs pysparkshell-fb00bc9289e61c8a-exec-1 | grep -A 15 "Configuring log-forwarding to Loki."
2024-10-14T07:20:14.451Z [sparkd] Configuring log-forwarding to Loki.
2024-10-14T07:20:14.454Z [sparkd] log-targets:
2024-10-14T07:20:14.454Z [sparkd]   grafana-agent-k8s:
2024-10-14T07:20:14.454Z [sparkd]     override: replace
2024-10-14T07:20:14.454Z [sparkd]     type: loki
2024-10-14T07:20:14.454Z [sparkd]     location: http://grafana-agent-k8s-0.grafana-agent-k8s-endpoints.spark-o11y.svc.cluster.local:3500/loki/api/v1/push
2024-10-14T07:20:14.454Z [sparkd]     services: [all]
2024-10-14T07:20:14.454Z [sparkd]     labels:
2024-10-14T07:20:14.454Z [sparkd]       product: charmed-spark
2024-10-14T07:20:14.454Z [sparkd]       app: spark
2024-10-14T07:20:14.454Z [sparkd]       app_id: spark-201e7bde966b447b99445ae77dd098bd
2024-10-14T07:20:14.454Z [sparkd]       user: rgildein
2024-10-14T07:20:14.454Z [sparkd]       pod: pysparkshell-fb00bc9289e61c8a-exec-1
2024-10-14T07:20:14.457Z [pebble] POST /v1/layers 280.628µs 200
2024-10-14T07:20:14.457Z [sparkd] Layer "logging" added successfully from "/tmp/rendered_log_layer.yaml"

Screenshot from 2024-10-15 13-14-06

spark-client.spark-submit \
                  --username spark --namespace spark \
                  --conf spark.kubernetes.driver.request.cores=100m \
                  --conf spark.kubernetes.executor.request.cores=100m \
                  --conf spark.kubernetes.container.image=docker.io/library/my-charmed-spark:3.4.2 \
                  --conf spark.executorEnv.LOKI_URL='http://grafana-agent-k8s-0.grafana-agent-k8s-endpoints.spark-o11y.svc.cluster.local:3500/loki/api/v1/push' \
                  --conf spark.kubernetes.driverEnv.LOKI_URL='http://grafana-agent-k8s-0.grafana-agent-k8s-endpoints.spark-o11y.svc.cluster.local:3500/loki/api/v1/push' \
                  --class org.apache.spark.examples.SparkPi \
                  local:///opt/spark/examples/jars/spark-examples_2.12-3.4.2.jar 1000

Screenshot from 2024-10-15 12-40-32

Add log forwarding layer yaml file, which is used in sparkd.sh and it
use environment variables to configure it.
The env used are:
 - LOKI_URL - url, which can be either Loki itself or Grafana-agent
 - SPARK_APPLICATION_ID - spark application id
 - SPARK_USER - user running these Pods / Jobs
 - SPARK_EXECUTOR_POD_NAME - Pod name

Signed-off-by: Robert Gildein <[email protected]>
@rgildein rgildein force-pushed the feat/DPE-5631/log-forwarding branch 3 times, most recently from a6e71e2 to ff76be4 Compare October 15, 2024 09:07
@rgildein rgildein requested review from deusebio and welpaolo October 15, 2024 09:48
@rgildein rgildein force-pushed the feat/DPE-5631/log-forwarding branch from ff76be4 to ef4eb73 Compare October 15, 2024 10:38
Copy link
Contributor

@deusebio deusebio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look fine. I only have some comments about the name of the labels. I would like to keep the labelling as similar as possible to the one that we have in the metrics.

@welpaolo @theoctober19th could you please check (and have a thought) that the label names are consistent with the one we push?

product: charmed-spark
flavour: $FLAVOUR
app: spark
app_id: $SPARK_APPLICATION_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo This should be spark_job_id to be consistent with the label in the metrics, see here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

services: [all]
labels:
product: charmed-spark
flavour: $FLAVOUR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo this should be role I believe

Copy link
Collaborator

@welpaolo welpaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me after you address the comment made by Enrico about the names of the labels

@theoctober19th theoctober19th self-requested a review October 22, 2024 07:11
Copy link
Member

@theoctober19th theoctober19th left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge with the change in the labels.

Signed-off-by: Robert Gildein <[email protected]>
Copy link
Contributor

@deusebio deusebio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

images/charmed-spark/pebble/log-layer.yaml Outdated Show resolved Hide resolved
Copy link
Collaborator

@welpaolo welpaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

As we discussed, it will be more appropriate to use `pod` as a label instead of `hostname`. The HOSTNAME environment variable represent Pod name.
@welpaolo welpaolo merged commit a1504c7 into 3.4-22.04/edge Oct 29, 2024
14 checks passed
@welpaolo welpaolo deleted the feat/DPE-5631/log-forwarding branch October 29, 2024 13:13
rgildein added a commit to canonical/spark-k8s-bundle that referenced this pull request Nov 6, 2024
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)
rgildein added a commit to canonical/spark-k8s-bundle that referenced this pull request Nov 6, 2024
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)
rgildein added a commit to canonical/spark-k8s-bundle that referenced this pull request Nov 14, 2024
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)
rgildein added a commit to canonical/spark-k8s-bundle that referenced this pull request Nov 19, 2024
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

Update TF plan and bundles to use history-revision rev33 due #53 and
integration-hub rev22, since this revision provides new relation.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)

Signed-off-by: Robert Gildein <[email protected]>
rgildein added a commit to canonical/spark-k8s-bundle that referenced this pull request Nov 19, 2024
This PR provides simple tests for checking the that Loki contain some
logs from Spark job.

Update TF plan and bundles to use history-revision rev33 due #53 and
integration-hub rev22, since this revision provides new relation.

related: [charmed-spark-rock#114](canonical/charmed-spark-rock#114)

Signed-off-by: Robert Gildein <[email protected]>
rgildein added a commit that referenced this pull request Nov 19, 2024
rgildein added a commit that referenced this pull request Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants