How to run k6 tests on amazon cloud - javascript

I want to run some load tests but my pc cannot handle more requests than the server. So I would like to run these tests on amazon ecs. Is there a way to run k6 on amazon cloud instead of their loadimpact cloud, if so, how?

Yes you can run k6 on Amazon cloud. The easiest way is probably to stand up a Centos or Ubuntu server in ec2 and then install k6 on it. This is how I have run it. Then install InfluxDB on the server also along with Grafana. Feed the output of the load test from k6 into InfluxDB and there is a community Grafana dashboard that will display stats from the load test. It will be close to using LoadImpact. You will still need to use LoadImpact to create the scripts if you are using the web browser plugin. But that is free.
You can run k6 inside a docker container too. I have not done that yet, but a coworker did. I am going to look into using ECS to run the container version of k6. But I have not tried it yet. You would still want an ec2 instance with InfluxDB to grab the data out of k6.

Related

How to restart a Node.js project?

I'm not a Node.js developer. So I have no idea how it works. I've been a PHP developer for over 8 years.
Because of some reason, I need to make a small change in a Node.js project which is live. All I have to do is changing a payment gateway token. I did it like this:
After pulling it on the server, users still go to the old payment gateway. So I guess I need to do a restart. (I'm saying so because, for PHP projects, when you change a config-related thing, you need to restart PHP).
Not sure should I restart what thing? Noted that, the server is Ubuntu 20.04 and uses Nginx to talk to Node.js. In other word, how can I see Node is running as what service on Linux?
Also, there are two files that I think I need to run the project again after restarting Node through one of them: index.js, server.js. Am I right?
And
Your Node.js script likely runs under a process that restarts the script in case it dies. There are several "run forever" wrappers, the most popular one is pm2. Find out which one is used in your project. Try pm2 list as the user your project executes under. If pm2 type pm2 restart app_name to restart your project.
Please check if it is a node.js project so you can write the command node index.js or node server.js with this command you can start your node server.

How to 'npm run build' on the server regularly

My webpage doesn't update contents too often, and users don't necessarily need to get the latest contents. So most pages are generated at server side, and serves static pages.
However, there will be database update. That should be visible on the web page. So I want how to 'npm run build' regularly while my server serves stably. How do I do that?
Normally you would want to have a corn job on your sever to trigger your npm run build regularly.
If that doesn't suites you, another approach is to take this totally to cloud, have your server expose an endpoint with appropriate security credentials, such as https://yourdomain.com/rebuild. Every time this endpoint is hit, it triggers your rebuild.
On the other hand, have a cloud based "cron-like" service (e.g. cron-job.org or Google Cloud Scheduler ) to trigger this endpoint with your customised schedule.
If your server is deployed via a CI/CD approach, depending on your CI/CD provider (e.g. Github Actions), you can also set the scheduler on the provider side to regularly rebuild & redeploy your server app. With Github Actions as example, it supports scheduler time based action triggers.
The first thing that comes to mind for "regular" tasks that will be simple and won't require much setup is a corn job. You can add 'npm run build'(obliviously pointing to the right directory) to crontab with any schedule you want. Here's a link with samples on how to setup cron.
But as you need to build your app and even run DB updates, it will be much safer and better to use CI solution. There are hundreds of them but my advice is to use Buddy. It has a free plan and super easy to work with.
With Buddy you can set up a pipeline that will SSH in your server and do the job. Or you can set up pipelines that will do all the actions at Buddy CI and then upload compiled files to the server.
Also, if we'd know what exactly 'npm run build' does, it will be easier to point for a more detailed answer.

Execute an EC2 command via the browser (Google Chrome)

I need to execute a command on AWS EC2 on demand, rather than a scheduled cron. How can I trigger a script on the command line on my EC2 by just using the web browser?
I have made an attempt via a webhook via Zapier but struggling to link this into the EC2 CLI.
Use Systems Manager Run Command or Fabric over SSH (example here, though it won't work from within a browser).

Connect to OpenVPN server through Node.js

I’m trying to create a GUI client for connecting to OpenVPN servers using electron and node but I’m struggling to figure out how to actually connect to the servers using the .ovpn files.
My question is what is the best way to connect to an OpenVPN server using node? Would it be best to Tun terminal commands like
“openvpn—config path to config”
Or is there another way applications like tunnelblick do it that might be easier or more efficient?
Hello I have been working with electron and ovpn on my last project, so here are a few tips.
VPNs require admin/root privilege in order to get setup, so running child_process.spawn on openvpn --config <path> will fail unless your electron app is being ran via sudo/admin privilege.
You can also use electron-sudo package, link here. This is basically a child process spawn with sudo/admin. Aka, app runs normally, but vpn command runs with sudo.
However, if your client is sketchy about giving you sudo/admin, the VPN must be ran separately prior to launching your app.
All in all its a admin/sudo thing.
Hope this helps.

How to use a browser on a remote server for an automated tests

I inherited a project where the person wrote tools to test our site's UI using JQuery and JS.
I don't know too much about it other than it requires a browser to be spawned and I think the tool uses JS to interact with iframes to see if it's the expected values.
My job is to get this tool to run on a remote server and post the results to Jenkins.
The remote test server and staging server is linux. From our staging server, I want to write a script to spawn a browser and run cmds from the tool to test our UI. I ran the following manually:
ssh -X user#remote_test_server /usr/bin/firefox
However, the remote server says:
Error: no display specified
Is there a way to spawn a browser for automated testing from one headless server to another? Thanks in advance for your help.
I faced a similar problem when I tried to automate a GUI installation program. While there are quite some different possibilities to choose from (e.g. Xnest, Xephyr?), I ended up using vncserver, because it's relatively easy to debug the GUI session this way.
You need to create a vncpassword file, I think:
mkdir -p $HOME/.vnc
chmod 0700 $HOME/.vnc
echo MyLittlePassword | vncpasswd -f > $HOME/.vnc/passwd
chmod 0600 $HOME/.vnc/passwd
Starting the server is then quite straightforward
vncserver
export DISPLAY=:1
/usr/bin/firefox&
...
Now it is possible to connect to the VNC server with a VNC viewer of your choice. But beware there may be no window manager, depending on the X startup scripts of your environment.
Shutting the server down
vncserver -kill :1
In the configuration of Jenkins project , specify the
Build Environment
Start Xvfb before the build, and shut it down after.
#

Categories