From a5f50487b5f48b4d24ded7f4624e0957c8c3797a Mon Sep 17 00:00:00 2001 From: job Date: Mon, 26 Feb 2024 15:40:33 +0000 Subject: [PATCH] Track the number of new files moving from 'staging' to 'validated cache' The OpenMetrics output shows per-repository counters for new files added, the main process and JSON output emit the sum of all new files. OK claudio@ --- usr.sbin/rpki-client/extern.h | 4 +++- usr.sbin/rpki-client/main.c | 6 +++++- usr.sbin/rpki-client/output-json.c | 3 ++- usr.sbin/rpki-client/output-ometric.c | 4 +++- usr.sbin/rpki-client/repo.c | 14 +++++++++++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index ebaede115d3..a27dd2123ae 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.209 2024/02/22 21:00:26 tb Exp $ */ +/* $OpenBSD: extern.h,v 1.210 2024/02/26 15:40:33 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -622,6 +622,7 @@ struct repostats { uint32_t extra_files; /* number of superfluous files */ uint32_t del_extra_files;/* number of removed extra files */ uint32_t del_dirs; /* number of dirs removed in cleanup */ + uint32_t new_files; /* moved from DIR_TEMP to DIR_VALID */ struct timespec sync_time; /* time to sync repo */ }; @@ -850,6 +851,7 @@ struct repo *repo_byid(unsigned int); int repo_queued(struct repo *, struct entity *); void repo_cleanup(struct filepath_tree *, int); int repo_check_timeout(int); +void repostats_new_files_inc(struct repo *, const char *); void repo_stat_inc(struct repo *, int, enum rtype, enum stype); void repo_tal_stats_collect(void (*)(const struct repo *, const struct repotalstats *, void *), int, void *); diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 933494a2540..231ddd821e7 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.251 2024/02/22 12:49:42 job Exp $ */ +/* $OpenBSD: main.c,v 1.252 2024/02/26 15:40:33 job Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -597,6 +597,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, rp = repo_byid(id); repo_stat_inc(rp, talid, type, STYPE_OK); + repostats_new_files_inc(rp, file); switch (type) { case RTYPE_TAL: st->tals++; @@ -786,6 +787,7 @@ sum_repostats(const struct repo *rp, const struct repostats *in, void *arg) out->extra_files += in->extra_files; out->del_extra_files += in->del_extra_files; out->del_dirs += in->del_dirs; + out->new_files += in->new_files; timespecadd(&in->sync_time, &out->sync_time, &out->sync_time); } @@ -1487,6 +1489,8 @@ main(int argc, char *argv[]) printf("Ghostbuster records: %u\n", stats.repo_tal_stats.gbrs); printf("Trust Anchor Keys: %u\n", stats.repo_tal_stats.taks); printf("Repositories: %u\n", stats.repos); + printf("New files moved into validated cache: %u\n", + stats.repo_stats.new_files); printf("Cleanup: removed %u files, %u directories\n" "Repository cleanup: kept %u and removed %u superfluous files\n", stats.repo_stats.del_files, stats.repo_stats.del_dirs, diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index 8ff1e7f6243..f19a49c5eee 100644 --- a/usr.sbin/rpki-client/output-json.c +++ b/usr.sbin/rpki-client/output-json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-json.c,v 1.43 2024/02/22 12:49:42 job Exp $ */ +/* $OpenBSD: output-json.c,v 1.44 2024/02/26 15:40:33 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * @@ -76,6 +76,7 @@ outputheader_json(struct stats *st) json_do_int("uniquevsps", st->repo_tal_stats.vsps_uniqs); json_do_int("vaps", st->repo_tal_stats.vaps); json_do_int("uniquevaps", st->repo_tal_stats.vaps_uniqs); + json_do_int("cachedir_new_files", st->repo_stats.new_files); json_do_int("cachedir_del_files", st->repo_stats.del_files); json_do_int("cachedir_del_dirs", st->repo_stats.del_dirs); json_do_int("cachedir_superfluous_files", st->repo_stats.extra_files); diff --git a/usr.sbin/rpki-client/output-ometric.c b/usr.sbin/rpki-client/output-ometric.c index b2775e159d5..c6d9f5869f4 100644 --- a/usr.sbin/rpki-client/output-ometric.c +++ b/usr.sbin/rpki-client/output-ometric.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-ometric.c,v 1.8 2024/02/22 12:49:42 job Exp $ */ +/* $OpenBSD: output-ometric.c,v 1.9 2024/02/26 15:40:33 job Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * @@ -141,6 +141,8 @@ repo_stats(const struct repo *rp, const struct repostats *in, void *arg) ol = olabels_new(keys, values); ometric_set_timespec(rpki_repo_duration, &in->sync_time, ol); + ometric_set_int_with_labels(rpki_repo_obj, in->new_files, + OKV("type", "state"), OKV("files", "new"), ol); ometric_set_int_with_labels(rpki_repo_obj, in->del_files, OKV("type", "state"), OKV("files", "deleted"), ol); ometric_set_int_with_labels(rpki_repo_obj, in->extra_files, diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 60354de7f0e..77967f4acc0 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.53 2024/02/22 12:49:42 job Exp $ */ +/* $OpenBSD: repo.c,v 1.54 2024/02/26 15:40:33 job Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1403,6 +1403,18 @@ repo_check_timeout(int timeout) return timeout; } +/* + * Update repo-specific stats when files are going to be moved + * from DIR_TEMP to DIR_VALID. + */ +void +repostats_new_files_inc(struct repo *rp, const char *file) +{ + if (strncmp(file, ".rsync/", strlen(".rsync/")) == 0 || + strncmp(file, ".rrdp/", strlen(".rrdp/")) == 0) + rp->repostats.new_files++; +} + /* * Update stats object of repository depending on rtype and subtype. */ -- 2.20.1