From: claudio Date: Thu, 30 Mar 2023 15:29:15 +0000 (+0000) Subject: Add the protocol used to sync the repository to the open-metric output. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d0837792d291bf4ea6c3561bff060825aa5f8f60;p=openbsd Add the protocol used to sync the repository to the open-metric output. OK tb@ --- diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index cb8994ecee5..563d43f9640 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.175 2023/03/13 19:51:49 job Exp $ */ +/* $OpenBSD: extern.h,v 1.176 2023/03/30 15:29:15 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -756,6 +756,7 @@ const char *repo_uri(const struct repo *); void repo_fetch_uris(const struct repo *, const char **, const char **); int repo_synced(const struct repo *); +const char *repo_proto(const struct repo *); int repo_talid(const struct repo *); struct repo *ta_lookup(int, struct tal *); struct repo *repo_lookup(int, const char *, const char *); diff --git a/usr.sbin/rpki-client/output-ometric.c b/usr.sbin/rpki-client/output-ometric.c index df6ef097671..412309d53a4 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.1 2022/12/15 12:02:29 claudio Exp $ */ +/* $OpenBSD: output-ometric.c,v 1.2 2023/03/30 15:29:15 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * @@ -26,11 +26,13 @@ #include "ometric.h" #include "version.h" -struct ometric *rpki_info, *rpki_completion_time, *rpki_duration; -struct ometric *rpki_repo, *rpki_obj, *rpki_ta_obj; -struct ometric *rpki_repo_obj, *rpki_repo_duration, *rpki_repo_state; +static struct ometric *rpki_info, *rpki_completion_time, *rpki_duration; +static struct ometric *rpki_repo, *rpki_obj, *rpki_ta_obj; +static struct ometric *rpki_repo_obj, *rpki_repo_duration; +static struct ometric *rpki_repo_state, *rpki_repo_proto; static const char * const repo_states[2] = { "failed", "synced" }; +static const char * const repo_protos[3] = { "rrdp", "rsync", "https" }; static void set_common_stats(const struct repostats *in, struct ometric *metric, @@ -118,6 +120,8 @@ repo_stats(const struct repo *rp, const struct repostats *in, void *arg) set_common_stats(in, rpki_repo_obj, ol); ometric_set_timespec(rpki_repo_duration, &in->sync_time, ol); ometric_set_state(rpki_repo_state, repo_states[repo_synced(rp)], ol); + if (repo_synced(rp)) + ometric_set_state(rpki_repo_proto, repo_proto(rp), ol); olabels_free(ol); } @@ -158,6 +162,10 @@ output_ometric(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, sizeof(repo_states) / sizeof(repo_states[0]), "rpki_client_repository_state", "repository state"); + rpki_repo_proto = ometric_new_state(repo_protos, + sizeof(repo_protos) / sizeof(repo_protos[0]), + "rpki_client_repository_protos", + "used protocol to sync repository"); /* * Dump statistics diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 0a2513c202e..08ab2a0d206 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.42 2023/03/29 17:03:29 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.43 2023/03/30 15:29:15 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1205,6 +1205,27 @@ repo_synced(const struct repo *rp) return 0; } +/* + * Return the protocol string "rrdp", "rsync", "https" which was used to sync. + * Result is only correct if repository was properly synced. + */ +const char * +repo_proto(const struct repo *rp) +{ + + if (rp->ta != NULL) { + const struct tarepo *tr = rp->ta; + if (tr->uriidx < tr->urisz && + strncasecmp(tr->uri[tr->uriidx], "rsync://", 8) == 0) + return "rsync"; + else + return "https"; + } + if (rp->rrdp != NULL) + return "rrdp"; + return "rsync"; +} + /* * Return the repository tal ID. */