k6 default output in docker image is too big - k6

I'm running a k6 docker image with some tests.
However, the output that I get is very different from what I would expect.
Instead of the usual output with just summary, I get those annoying running and default prints.
How can I show just the end of test summary?

Those console messages can be suppressed with the -q / --quiet flag as documented here.

Related

Getting RStudio in Docker Environment Command Window as opposed to browser?

This is a question related to using docker to run scripts of RStudio. The problem I'm having is that the person evaluating the results I'm getting wants to have it so that they type in ./test.sh in the command window, that runs my R script, and a csv of my results prints out to the local directory.
Is it possible to get the rocker rstudio to appear in the command window as opposed to having to log into the browser to use rstudio? It seems all the resources online say something along the lines of put -p 8002:8787 and -d in the docker line of code, but this makes it so you have to go to a local browser to actually run your R script.
I've found this code snippet works, but is there an alternative to using \bin\bash at the end so that the rstudio commands can just stay in the window?
$ docker run -e PASSWORD=MYPASSWORD -v "$(pwd):/data:ro" -v "$(pwd):/workdir" -it thatguy /bin/bash
Or, better yet, is there a way to put this docker run command in my Dockerfile so that when I run my $ docker build this line just runs automatically?

Different behavior when Rscript & rstan is run as a cron job

I try to run an R script at regular intervals to update a webpage. The script runs fine when called from the terminal like this:
/usr/local/bin/Rscript /Users/me/path/myscript.R
However, if I try running it as a cron job, I get an error. I add the job to crontab like this:
46 10 * * * /usr/local/bin/Rscript '/Users/me/path/myscript.R' >> '/Users/me/path/mylog.log' 2>&1
The script does run in R, but aborts due to an error. Specifically, I fit some models using rstan, and get an initialization error. (The error only applies to some models, while others still run fine.) The initialization values are valid by definition, but do not seem to be used properly. It is like rstan is doing math differently (and wrong) when it is run through cron.
The session info from R is identical whether I run the script in the terminal or as a cron job. My question is what else might still differ depending on how the script is run. Could rstan be using a different version of C++ when run as a cron job? Are there other paths I may need to set to get this to work correctly?
Update: The script also works if I run it using R CMD BATCH in terminal, but not if I use R CMD BATCH in a cron job. Using launchd triggers the same issue. I also tried using CmdStan through cmdstanr, and the same same thing happens: Runs fine until added to a cron job.
Edit 2: The models I thought ran fine in cron, were not actually fine. The results were wrong, until I used the fix explained below.
It looks like I finally managed to fix this, and I'm posting my solution here for anyone who encounters the same problem.
I ran env in terminal to see my current user environment. I copy-pasted the full output to the top of my crontab file. (Simply adding the PATH variable was not sufficient. I suppose it was SHELL or perhaps both PATH and SHELL that did the trick, but I haven't explored this further.)
To edit my user's crontab, I ran crontab -e, then pressed i to edit the file, pasted everything from env at the top of the file, stopped editing by pressing ctrl + c, and quit by typing :wq and hitting enter.

How to temporarily Turn Off zscaler using Windows Command Line?

I am trying to automate a docker command in R. However, in order to run the command, zscaler must be turned off for it to work.
The R script is as follows:
shell(cmd = "docker some command", shell = "CMD.EXE")
It creates an error because zscaler is on but works when it's off.
I would like to write a command that turns off zscaler before this R script and then another one after to turn it back on. Is such a command possible?

Let Docker image build fail when R package installation returns error

I am trying to create a custom Docker image based on Rocker using Dockerfile. In the Dockerfile I am pulling my own R package from a custom GitLab server using:
RUN R -e "devtools::install_git('[custom gitlab server]', quiet = FALSE)"
Everything usually works, but I have noticed that when the GitLab server is down, or the machine running Docker is low on RAM memory, the package does not install correctly and returns an error message in the R console. This behavior is to be expected. However, Docker does not notice the error produced by R and continues evaluating the rest of the Dockerfile. I would like Docker to fail building the image when this occurs. In that way, I could ultimately prevent automatic deployment of the incomplete Docker container by Kubernetes.
So far I have thought of two potential solutions, but I am struggling with the execution:
R level: Wrap tryCatch() around devtools::install_git to catch the error. But then what? Use stop? Will this cause the Docker building process to stop as well? Could withCallingHandlers() be used?
Dockerfile level: Use a shell command to check for errors? I cannot find the contents of R --help as I do not have a Linux machine at the moment. So I am not sure of what R -e actually does (execute I presume) and which other commands could be passed along with R.
It seems that a similar issue is discussed here and here, but the I do not understand how they have solved it.
Thus how to make sure no Docker image ends up running on the Kubernetes cluster without the custom package?
The Docker build process should stop once one of the commands in the Dockerfile returns a non zero status.
install_git doesn't seem to throw an error when the package wasn't installed successfully, so the execution keeps on.
An obvious way to go would be to wrap the installation inside a dedicated R script and throw an error if it didn't finish successfully, which would then stop the build.
So I would suggest something like this ...
Create installation script install_gitlab.R:
### file install_gitlab.R
## change repo- and package name!!
repo <- '[custom gitlab server]'
pkgname <- 'testpackage'
devtools::install_git(repo, quiet = FALSE)
stopifnot(pkgname %in% installed.packages()[,'Package'])
Modify your Dockerfile accordingly (replace the install_git line):
...
Add install_gitlab.R /runscripts/install_gitlab.R
RUN Rscript /runscripts/install_gitlab.R
...
One thing to keep in mind is, this approach assumes the package you're trying to install is NOT installed prior to calling the command.
If you're using a rocker image, they already have the littler package installed, which has the handy installGithub.r script. I believe it should already have the functionality you want. If not, it at least simplifies the running of the custom install_github.r script.
A docker RUN command using littler just looks like:
RUN installGithub.r "yourRepo"

Run r script in background on Ubuntu server

I am working on an ubuntu server. I have an R Script which will run for several days. How would I run it in the background - that when I log out it still runs?!
When I try R script.R it says ARGUMENT 'script.R' __ignored__
First off, to run an R script in batch mode, you have several possibilities; I use the following, which works well:
Rscript scriptname.r
This, however, will run the script in the foreground. This isn’t a problem in tmux per se — just run it in a background tab. However, you can of course run it in the background in the usual way — append &:
Rscript scriptname.r &
Again, this needs to be run inside tmux (or similar) to stay alive once you log out.

Resources