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

Setting the customized path in handleSummary #69

Open
Storkycold opened this issue Nov 12, 2024 · 5 comments
Open

Setting the customized path in handleSummary #69

Storkycold opened this issue Nov 12, 2024 · 5 comments

Comments

@Storkycold
Copy link

Storkycold commented Nov 12, 2024

Dear k6-reporter Community,

I hope this finds you well.

I am currently using the htmlReport function from the k6-reporter package to generate HTML reports for my distributed k6 test results, and I am encountering a specific challenge.

Would it be possible to specify the output path for summary.html within handleSummary? I understand that the default path is /home/k6 in the k6 runner pod. However, I would like to save it directly to /bfai/programs/report-summary on the server, as I plan to volume mount this path in nginx to view summary.html via the server.

My goal is to include additional code to define the file path for summary.html explicitly.

export function handleSummary(data) {
  return {
    "summary.html": htmlReport(data),
  };
}

I would deeply appreciate your consideration.

Best regards,
Shin

@marijamitevska-rldatix
Copy link

marijamitevska-rldatix commented Nov 12, 2024

Hello.

The file name and output path can be changed as needed. For example, here there is a timestamp added to the filename, and a relative file path is specified as well, assuming /bfai is in the project root directory, which can be changed depending on your directory structure:

export function handleSummary(data) {
	const filePath = `./bfai/programs/report-summary/${formatDate(new Date())}--summary.html`;
	return {
		stdout: textSummary(data, { indent: ' ', enableColors: true }),
		[filePath]: htmlReport(data),
	};
}

@Storkycold
Copy link
Author

Storkycold commented Nov 14, 2024

Hello, thank you for the comment.

I have reviewed it carefully, but your comment appears to be on the file name rather than the path where the file will be saved.

I think your process might be as follows.

#inside the k6 runner pod
ls
/home/k6 ./bfai/programs/report-summary/${formatDate(new Date())}--summary.html

However, I want summary.html to be actually saved in the server path, which is /bfai/program/report-summary summary.html.

#inside the k6 runner pod
ls
/home/k6 summary.html

#path inside the server 
pwd 
/bfai/program/report-summary summary.html 

So, I was wondering if there’s a way to achieve this without using a volume mount.

If there are no other options, I am considering using a volume mount.


To further elaborate on this comment, I was wondering if setting ENV variable is possible.

I have some anticipated example. By executing the testrun-test.yaml as k6 distributed test, at first I thought the environment variable SUMMARY_NAME would be conveyed to const fileName in test.js. And eventually the output summary name would be SUMMARY_NAME.html also.

testrun-test.yaml
apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: test
  namespace: k6-operator-system
spec:
  parallelism: 2
  cleanup: post
  script:
    volumeClaim:
      name: k6-script-volume-claim
      file: test.js
  runner:
    securityContext:
      runAsUser: 0
    resources:
      limits:
        cpu: 20
        memory: 6Gi
      requests:
        cpu: 20
        memory: 6Gi
    env:
      - name: SUMMARY_NAME
        value: "SUMMARY_NAME.html"
#test.js 
export const fileName = __ENV.SUMMARY_NAME;

export function handleSummary(data, fileName) {
  return { [`${fileName}.html`]: htmlReport(data) };
}

However, after the k6 distributed test, the result showed up as undefined.html. I think ENV.SUMMARY_NAME does not work as I expected. The thing is, this setting works in the local test. The result summary file successfully shows SUMMARY_NAME.html

/home/k6 # ls
undefined.html

If this process is eventually resolved, I think setting the customized path would be also available; since I can just set the customized environment variable to save the summary result.

@marijamitevska-rldatix
Copy link

I am not sure if you can save the file directly from handleSummary() from one pod on another in the same cluster. I think you would first need the file created on the runner pod and then you can copy it elsewhere, maybe with kubectl cp first to your local machine and then again to copy it to another pod, or maybe try some kind of pod to pod copying, or maybe use PersistentVolume and PersistentVolumeClaim to have a shared filesystem for the cluster.

@fjzcxs
Copy link

fjzcxs commented Dec 5, 2024

您好,感谢您的评论。

我已经仔细检查过,但您的评论似乎是针对文件名,而不是文件保存的路径。

我认为您的流程可能如下。

#inside the k6 runner pod
ls
/home/k6 ./bfai/programs/report-summary/${formatDate(new Date())}--summary.html

但是,我希望summary.html实际保存在服务器路径中,即/bfai/program/report-summary summary.html

#inside the k6 runner pod
ls
/home/k6 summary.html

#path inside the server 
pwd 
/bfai/program/report-summary summary.html 

所以,我想知道是否有办法在不使用卷挂载的情况下实现这一点。

如果没有其他选择,我正在考虑使用卷挂载。

为了进一步阐述这个评论,我想知道是否可以设置 ENV 变量。

我有一些预期的例子。通过执行 testrun-test.yaml 作为 k6 一轮测试,我认为环境变量SUMMARY_NAME会被传递到const fileName最终test.js。输出的摘要名称是SUMMARY_NAME.html

测试运行-测试.yaml

apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: test
  namespace: k6-operator-system
spec:
  parallelism: 2
  cleanup: post
  script:
    volumeClaim:
      name: k6-script-volume-claim
      file: test.js
  runner:
    securityContext:
      runAsUser: 0
    resources:
      limits:
        cpu: 20
        memory: 6Gi
      requests:
        cpu: 20
        memory: 6Gi
    env:
      - name: SUMMARY_NAME
        value: "SUMMARY_NAME.html"
#test.js 
export const fileName = __ENV.SUMMARY_NAME;

export function handleSummary(data, fileName) {
  return { [`${fileName}.html`]: htmlReport(data) };
}

但是,在k6全面测试之后,结果显示为undefined.html。我认为ENV.SUMMARY_NAME没有按预期工作。问题是,此设置在本地测试中有效。结果摘要文件成功显示SUMMARY_NAME.html

/home/k6 # ls
undefined.html

如果这个过程得到最终解决,我认为设置自定义路径也是可行的;因为我可以设置自定义的环境变量来保存摘要结果。

Hello, how do you go into the pod to view the output file, I understand that this summary.html file will be generated after the end of the test, but the pod is not allowed to enter the pod after the end of the view

@Storkycold
Copy link
Author

Storkycold commented Dec 19, 2024

Sorry for the late reply.

You need to add volumeMounts in your testrun script to save your summary.html file, since pod is too volatile to save it.

Methodology is as follows.

Testrun Script

apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: testrun-module 
  namespace: k6-operator-system
...
# add volumeMounts in testrun script 
    volumeMounts:
      - name: k6-report-summary-volume
        mountPath: /home/k6
    volumes:
      - name: k6-report-summary-volume
        persistentVolumeClaim:
          claimName: report-summary-volume-claim

PV, PVC

apiVersion: v1
kind: PersistentVolume
metadata:
  name: k6-report-summary-volume
spec:
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/bfai/programs/report-summary" # path to save summary.html file 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: report-summary-volume-claim
spec:
  storageClassName: ""
  volumeName: k6-report-summary-volume
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

Since I'm using k6-operator-system namespace in Kubernetes to test k6 script, create PV and PVC like this.

1. kubectl get pvc -n k6-operator-system
NAME                          STATUS   VOLUME                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
report-summary-volume-claim   Bound    k6-report-summary-volume   1Gi        RWX                           <unset>                 34d

2. kubectl get pv -A
k6-report-summary-volume                      1Gi        RWX            Retain           Bound      k6-operator-system/report-summary-volume-claim                                                                                  <unset>                          34d

3. kubectl describe pv k6-report-summary-volume
Name:            k6-report-summary-volume
Labels:          <none>
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:
Status:          Bound
Claim:           k6-operator-system/report-summary-volume-claim
Reclaim Policy:  Retain
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        1Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /bfai/programs/report-summary
    HostPathType:
Events:            <none>

So in my case, by adding k6-report-summary-volume

hostpath: /bfai/programs/report-summary <-> k6 runner pod path: /home/k6 (default path for summary.html file)

is mounted together.

Therefore, right after thesummary.html file is generated, it is directly saved into hostpath, which is /bfai/programs/report-summary.

Hope this helps!

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

No branches or pull requests

3 participants