unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Bruno Victal <mirai@makinata.eu>
Cc: 60788@debbugs.gnu.org
Subject: [bug#60788] [PATCH] services: Add vnstat-service-type.
Date: Mon, 16 Jan 2023 13:42:05 -0500	[thread overview]
Message-ID: <87o7qy48zm.fsf@gmail.com> (raw)
In-Reply-To: <95b646eb6b23dec213cba43b6e4e7ddc4a601d0f.1673640404.git.mirai@makinata.eu> (Bruno Victal's message of "Fri, 13 Jan 2023 20:07:36 +0000")

Hello!

Bruno Victal <mirai@makinata.eu> writes:

[...]

> @@ -45,6 +48,10 @@ (define-module (gnu services monitoring)
>              prometheus-node-exporter-web-listen-address
>              prometheus-node-exporter-service-type
 
> +            vnstat-configuration
> +            vnstat-configuration?
> +            vnstat-service-type
> +

Normally, all the accessors are exported, otherwise there's no means to
introspect a vnstat-configuration, which may be useful at the REPL.

[...]

> +\f
> +;;;
> +;;; vnstat daemon
> +;;;
> +
> +(define* (camelfy-field-name field-name #:key (dromedary? #f))
> +  (match (string-split (symbol->string field-name) #\-)
> +    ((head tail ...)
> +     (string-join (cons (if dromedary? head (string-upcase head 0 1))
> +                        (map string-capitalize tail)) ""))))

I'd name this pascal-case-field-name, and drop the apparently unused
dromerady? argument (fun, though :-)).  If we need it, we could
introduce a 2nd camel-case-field-name.

> +(define (dock-field-name field-name)
> +  "Drop rightmost '?' character"
> +  (let ((str (symbol->string field-name)))
> +    (if (string-suffix? "?" str)
> +        (string->symbol (string-drop-right str 1))
> +        field-name)))

I'm not sure about the meaning of 'dock' in this procedure name.
Perhaps 'strip-trailing-?-character' would be better?

> +(define (vnstat-serialize-string field-name value)
> +  #~(format #f "~a ~s~%"
> +            #$(camelfy-field-name field-name)
> +            #$value))
> +
> +(define vnstat-serialize-integer vnstat-serialize-string)
> +
> +(define (vnstat-serialize-boolean field-name value)
> +  #~(format #f "~a ~a~%"
> +            #$(camelfy-field-name (dock-field-name field-name))
> +            #$(if value 1 0)))
> +
> +(define (vnstat-serialize-alist field-name value)
> +  (generic-serialize-alist string-append
> +                           (lambda (iface val)
> +                             (vnstat-serialize-integer
> +                              (format #f "MaxBW~a" iface) val))
> +                           value))
> +
> +(define-maybe string  (prefix vnstat-))
> +(define-maybe integer (prefix vnstat-))
> +(define-maybe boolean (prefix vnstat-))
> +(define-maybe alist   (prefix vnstat-))
> +
> +;; Documentation strings from vnstat.conf manpage adapted to texinfo.
> +;; vnstat checkout: v2.10, commit b3408af1c609aa6265d296cab7bfe59a61d7cf70
> +(define-configuration vnstat-configuration
> +  (package
> +    (file-like vnstat)
> +    "The vnstat package."
> +    empty-serializer)
> +
> +  (database-dir
> +   (string "/var/lib/vnstat")
> +   "\
> +Specifies the directory where the database is to be stored.
> +A full path must be given and a leading '/' isn't required.")  
> +
> +  (5-minute-hours
> +   (maybe-integer 48)
> +   "\
> +Data retention duration for the 5 minute resolution entries. The configuration
> +defines for how many past hours entries will be stored. Set to @code{-1} for
> +unlimited entries or to @code{0} to disable the data collection of this
> +resolution.")
> +
> +  (64bit-interface-counters
> +   (maybe-integer -2)
> +   "\
> +Select interface counter handling. Set to @code{1} for defining that all interfaces
> +use 64-bit counters on the kernel side and @code{0} for defining 32-bit counter. Set
> +to @code{-1} for using the old style logic used in earlier versions where counter
> +values within 32-bits are assumed to be 32-bit and anything larger is assumed to
> +be a 64-bit counter. This may produce false results if a 64-bit counter is
> +reset within the 32-bits. Set to @code{-2} for using automatic detection based on
> +available kernel datastructures.")

Please reflow these paragraphs so they fit under the 80 characters width
limit.  Perhaps drop the \ escape, as it doesn't provide much and looks
a bit worst, in my opinion.  Each sentence should be separated by two
spaces (that's a Texinfo convention).  This comment applies to all
similar documentation texts.

> +  (always-add-new-interfaces?
> +   (maybe-boolean #t)
> +   "\
> +Enable or disable automatic creation of new database entries for interfaces not
> +currently in the database even if the database file already exists when the
> +daemon is started. New database entries will also get created for new interfaces
> +seen while the daemon is running. Pseudo interfaces lo, lo0 and sit0 are always
> +excluded from getting added.")

The lo, lo0 and sit0 could use a @samp{} or decorator.

[...]

> +(define (vnstat-serialize-configuration config)
> +  (mixed-text-file
> +   "vnstat.conf"
> +   (serialize-configuration config vnstat-configuration-fields)))
> +
> +(define (vnstat-shepherd-service config)
> +  (let ((config-file (vnstat-serialize-configuration config)))
> +    (match-record config <vnstat-configuration> (package pid-file)
> +      (shepherd-service
> +       (documentation "Run vnstatd.")
> +       (requirement `(networking))
> +       (provision '(vnstatd))
> +       (start #~(make-forkexec-constructor
> +                 (list #$(file-append package "/sbin/vnstatd")
> +                       "--daemon"
> +                       "--config" #$config-file)
> +                 #:pid-file #$pid-file))
> +       (stop #~(make-kill-destructor))
> +       (actions
> +        (list (shepherd-configuration-action config-file)

I don't understand what (shepherd-configuration-action config-file)
corresponds to?

> +              (shepherd-action
> +               (name 'reload)
> +               (documentation "Reload vnstatd.")
> +               (procedure
> +                #~(lambda (pid)
> +                    (if pid
> +                        (begin
> +                          (kill pid SIGHUP)
> +                          (format #t
> +                                  "Issued SIGHUP to vnstatd (PID ~a)."
> +                                  pid))
> +                        (format #t "vnstatd is not running.")))))))))))

> +(define (vnstat-account-service config)
> +  (match-record config <vnstat-configuration> (daemon-group daemon-user)
> +    (if (every maybe-value-set? (list daemon-group daemon-user))
> +        (list
> +         (user-group
> +          (name daemon-group)
> +          (system? #t))
> +         (user-account
> +          (name daemon-user)
> +          (group daemon-group)
> +          (system? #t)
> +          (home-directory "/var/empty")
> +          (shell (file-append shadow "/sbin/nologin"))))
> +        '())))
> +
> +(define vnstat-service-type
> +  (service-type
> +   (name 'vnstat)
> +   (description "vnStat network-traffic monitor service.")
> +   (extensions
> +    (list (service-extension shepherd-root-service-type
> +                             (compose list vnstat-shepherd-service))
> +          (service-extension account-service-type
> +                             vnstat-account-service)))
> +   (default-value (vnstat-configuration))))

The rest LGTM (a system test would be nice, but since the Shepherd
service definition is straightforward, it could come later, when the
need arise).

That appears carefully crafted, thank you!  Could you send a v2 with my
above comments addressed, keeping me in CC?

-- 
Thanks,
Maxim




  parent reply	other threads:[~2023-01-16 18:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 20:07 [bug#60788] [PATCH] services: Add vnstat-service-type Bruno Victal
2023-01-14 21:06 ` [bug#60788] [PATCH v2] " Bruno Victal
2023-01-16 18:42 ` Maxim Cournoyer [this message]
2023-01-16 19:31   ` [bug#60788] [PATCH] " Bruno Victal
2023-01-16 19:56     ` Maxim Cournoyer
2023-01-18  0:34 ` [bug#60788] [PATCH v2] " Bruno Victal
2023-01-18  0:37 ` [bug#60788] [PATCH v2] services: vnstat: Use least-authority-wrapper Bruno Victal
2023-02-02 14:21 ` [bug#60788] [PATCH v3] services: Add vnstat-service-type Bruno Victal
2023-02-07 14:25 ` [bug#60788] [PATCH v4] " Bruno Victal
2023-02-09  3:34   ` [bug#60788] [PATCH] " Maxim Cournoyer
2023-02-09  4:19     ` Bruno Victal
2023-02-09 13:31       ` Maxim Cournoyer
2023-02-10 13:15 ` [bug#60788] [PATCH v5] " Bruno Victal
2023-02-10 14:07   ` Maxim Cournoyer
2023-02-10 14:14 ` [bug#60788] [PATCH v6] " Bruno Victal
2023-03-22 16:15 ` [bug#60788] [PATCH v7] " Bruno Victal
2023-04-03 14:14 ` [bug#60788] [PATCH v8] " Bruno Victal
2023-04-04 13:08 ` [bug#60788] [PATCH v9] " Bruno Victal
2023-04-07 15:22   ` [bug#60788] [PATCH] " Ludovic Courtès
2023-04-07 20:04     ` Maxim Cournoyer
2023-04-20 10:03       ` [bug#60788] Policy for system tests? Ludovic Courtès
2023-04-08 12:40     ` [bug#60788] [PATCH] services: Add vnstat-service-type Bruno Victal
2023-04-20 10:09       ` Ludovic Courtès
2023-05-05  0:18 ` [bug#60788] [PATCH v10 1/3] " Bruno Victal
2023-05-11 14:33   ` bug#60788: " Ludovic Courtès
2023-05-05  0:18 ` [bug#60788] [PATCH v10 2/3] services: inetd: Export accessors Bruno Victal
2023-05-05  0:18 ` [bug#60788] [PATCH v10 3/3] tests: Add vnstat tests Bruno Victal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7qy48zm.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=60788@debbugs.gnu.org \
    --cc=mirai@makinata.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).