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

Remaining number of seconds to midnight #4107

Closed
Zabrane opened this issue May 17, 2024 · 5 comments
Closed

Remaining number of seconds to midnight #4107

Zabrane opened this issue May 17, 2024 · 5 comments

Comments

@Zabrane
Copy link

Zabrane commented May 17, 2024

Expected Behavior

I'm trying to calculate the remaining number of seconds till midnight and use it in the Cache-Control HTTP header:

sub vcl_backend_response {
set resp.http.X-Seconds-To-Midnight = std.integer(duration=std.time(regsub(now, "^(.+?)\d{2}:\d{2}:\d{2}(.+?)$", "\100:00:00\2")) + 1d - now);
 set beresp.http.Cache-Control = "public, max-age=" + resp.http.X-Seconds-To-Midnight + ", must-revalidate";
}

Current Behavior

An error in the VCL when calling duration.

Possible Solution

No response

Steps to Reproduce (for bugs)

No response

Context

I'm unable to use the function std.integer(duration=...

Varnish Cache version

varnishd (varnish-6.0.13 revision a395739)

Operating system

Debian GNU/Linux 10 (buster)

Source of binary packages used (if any)

No response

@Zabrane Zabrane changed the title Remaning number of seconds to midnight Remaining number of seconds to midnight May 17, 2024
@gquintard
Copy link
Member

Help us here :-) what's the error?

@Zabrane
Copy link
Author

Zabrane commented May 18, 2024

Hi @gquintard

My bad, forgot the error message. Here you are:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

$ varnishd -V                                                                                                                       
varnishd (varnish-6.0.13 revision a395739fa63cddec305142eabefec0a4fd5339e7)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2024 Varnish Software

$ systemctl start varnish
$ journalctl -xu varnish
[...]
-- The job identifier is 4090832.
May 18 16:33:27 XXXX varnishd[29974]: Error:
May 18 16:33:27 XXXX varnishd[29974]: Message from VCC-compiler:
May 18 16:33:27 XXXX varnishd[29974]: Unknown argument 'duration'
May 18 16:33:27 XXXX varnishd[29974]: ('/etc/default.vcl' Line 187 Pos 55)
May 18 16:33:27 XXXX varnishd[29974]:     set resp.http.X-Seconds-To-Midnight = std.integer(duration=std.time(regsub(now, "^(.+?)\d{2}:\d{2}:\d{2}(.+?)$", "\100:00:00\2")) + 1d
May 18 16:33:27 XXXX varnishd[29974]: ------------------------------------------------------########-----------------------------------------------------------------------------
May 18 16:33:27 XXXX varnishd[29974]: While compiling function call:
May 18 16:33:27 XXXX varnishd[29974]: ('/etc/default.vcl' Line 187 Pos 43) -- (Pos 54)
May 18 16:33:27 XXXX varnishd[29974]:     set resp.http.X-Seconds-To-Midnight = std.integer(duration=std.time(regsub(now, "^(.+?)\d{2}:\d{2}:\d{2}(.+?)$", "\100:00:00\2")) + 1d
May 18 16:33:27 XXXX varnishd[29974]: ------------------------------------------############-------------------------------------------------------------------------------------
May 18 16:33:27 XXXX varnishd[29974]: Running VCC-compiler failed, exited with 2
May 18 16:33:27 XXXX varnishd[29974]: VCL compilation failed
May 18 16:33:27 XXXX systemd[1]: varnish.service: Control process exited, code=exited, status=255/EXCEPTION
-- Subject: Unit process exited

Varnish 6.0.13 was installed on a Debian Buster by following these instructions.

Let me know if you need something else or you want me to perform any test.

@gquintard
Copy link
Member

Thanks for that. It's just that on 6.0, that option doesn't exist: https://varnish-cache.org/docs/6.0/reference/vmod_generated.html

You will need to either upgrade to something more recent, like 7.5, or use std.time2integer()

@Zabrane
Copy link
Author

Zabrane commented May 19, 2024

Thanks @gquintard. I gonna try the std.time2integer().

Any reason why std vmod wasn't backported to 6.x?

We were scared a bit to use 7.5 because of the VSV00014 vulnerability.

@gquintard
Copy link
Member

7.5 isn't affected, so that's actually a great reason to use it :-)

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

2 participants