From 1e91be67c0c3bb58e87f0f4067a677e8ac5c9e87 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Thu, 16 Jan 2025 16:28:28 -0500 Subject: [PATCH] feat: configure telemetry resolves #108 --- cmd/configure/configure.go | 1 + cmd/configure/telemetry.go | 76 +++++++++++++++++++ .../docs/reference/nodekit_configure.md | 3 +- .../reference/nodekit_configure_telemetry.md | 35 +++++++++ man/nodekit_configure.md | 3 +- man/nodekit_configure_telemetry.md | 38 ++++++++++ 6 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 cmd/configure/telemetry.go create mode 100644 docs/src/content/docs/reference/nodekit_configure_telemetry.md create mode 100644 man/nodekit_configure_telemetry.md diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index 0aa38fc2..8423fb2a 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -41,6 +41,7 @@ var Cmd = &cobra.Command{ func init() { Cmd.AddCommand(serviceCmd) + Cmd.AddCommand(telemetryCmd) } const RunningErrorMsg = "algorand is currently running. Please stop the node with *node stop* before configuring" diff --git a/cmd/configure/telemetry.go b/cmd/configure/telemetry.go new file mode 100644 index 00000000..6b20281c --- /dev/null +++ b/cmd/configure/telemetry.go @@ -0,0 +1,76 @@ +package configure + +import ( + "github.com/algorandfoundation/nodekit/cmd/utils" + "github.com/algorandfoundation/nodekit/cmd/utils/explanations" + "github.com/algorandfoundation/nodekit/internal/algod" + "github.com/algorandfoundation/nodekit/internal/system" + "github.com/algorandfoundation/nodekit/ui/style" + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" + "github.com/spf13/cobra" +) + +var dataDir = "" +var telemetryEndpoint string +var telemetryName string + +var telemetryShort = "Configure telemetry for the Algorand daemon" +var NodelyTelemetryWarning = "The default telemetry provider is Nodely." +var telemetryLong = lipgloss.JoinVertical( + lipgloss.Left, + style.Purple(style.BANNER), + "", + style.Bold(telemetryShort), + "", + style.BoldUnderline("Overview:"), + "When a node is run using the algod command, before the script starts the server,", + "it configures its telemetry based on the appropriate logging.config file.", + "When a node’s telemetry is enabled, a telemetry state is added to the node’s logger", + "reflecting the fields contained within the appropriate config file", + "", + style.Yellow.Render(NodelyTelemetryWarning), +) + +var telemetryCmd = utils.WithAlgodFlags(&cobra.Command{ + Use: "telemetry", + Short: telemetryShort, + Long: telemetryLong, + Run: func(cmd *cobra.Command, args []string) { + log.Warn(style.Yellow.Render(explanations.SudoWarningMsg)) + sudoExists := system.CmdExists("sudo") + if !sudoExists { + log.Fatal("sudo is not installed, ensure it is available on your system in the PATH.") + } + diagExists := system.CmdExists("diagcfg") + if !diagExists { + log.Fatal("diagcfg is not installed, ensure it is available on your system in the PATH.") + } + + dataDir, err := algod.GetDataDir(dataDir) + + err = system.RunAll(system.CmdsList{ + {"sudo", "diagcfg", "-d", dataDir, "telemetry", "endpoint", "-e", telemetryEndpoint}, + {"sudo", "diagcfg", "-d", dataDir, "telemetry", "name", "-n", telemetryName}, + {"sudo", "diagcfg", "-d", dataDir, "telemetry", "enable"}, + }) + if err != nil { + log.Fatal(err) + } + log.Debug("Restarting node...") + err = algod.Stop() + if err != nil { + log.Fatal(err) + } + err = algod.Start() + if err != nil { + log.Fatal(err) + } + log.Debug("Node restarted successfully.") + }, +}, &dataDir) + +func init() { + telemetryCmd.Flags().StringVarP(&telemetryEndpoint, "endpoint", "e", "https://tel.4160.nodely.io", "Sets the \"URI\" property") + telemetryCmd.Flags().StringVarP(&telemetryName, "name", "n", "anon", "Enable Algorand remote logging with specified node name") +} diff --git a/docs/src/content/docs/reference/nodekit_configure.md b/docs/src/content/docs/reference/nodekit_configure.md index ddba61e0..3820971e 100644 --- a/docs/src/content/docs/reference/nodekit_configure.md +++ b/docs/src/content/docs/reference/nodekit_configure.md @@ -22,5 +22,6 @@ Note: This is still a work in progress. Expect bugs and rough edges. * [nodekit](/reference/nodekit) - Manage Algorand nodes from the command line * [nodekit configure service](/reference/nodekit/configure/service) - Install service files for the Algorand daemon. +* [nodekit configure telemetry](/reference/nodekit/configure/telemetry) - Configure telemetry for the Algorand daemon -###### Auto generated by spf13/cobra on 7-Jan-2025 +###### Auto generated by spf13/cobra on 16-Jan-2025 diff --git a/docs/src/content/docs/reference/nodekit_configure_telemetry.md b/docs/src/content/docs/reference/nodekit_configure_telemetry.md new file mode 100644 index 00000000..7e66a3c9 --- /dev/null +++ b/docs/src/content/docs/reference/nodekit_configure_telemetry.md @@ -0,0 +1,35 @@ +--- +title: "nodekit configure telemetry" +slug: "reference/nodekit/configure/telemetry" +--- +## Synopsis + + +Configure telemetry for the Algorand daemon + +Overview: +When a node is run using the algod command, before the script starts the server, +it configures its telemetry based on the appropriate logging.config file. +When a node’s telemetry is enabled, a telemetry state is added to the node’s logger +reflecting the fields contained within the appropriate config file + +The default telemetry provider is Nodely. + +``` +nodekit configure telemetry [flags] +``` + +### Options + +``` + -d, --datadir string Data directory for the node + -e, --endpoint string Sets the "URI" property (default "https://tel.4160.nodely.io") + -h, --help help for telemetry + -n, --name string Enable Algorand remote logging with specified node name (default "anon") +``` + +### SEE ALSO + +* [nodekit configure](/reference/nodekit/configure) - Change settings on the system (WIP) + +###### Auto generated by spf13/cobra on 16-Jan-2025 diff --git a/man/nodekit_configure.md b/man/nodekit_configure.md index 6782d6f0..5e8f6e1f 100644 --- a/man/nodekit_configure.md +++ b/man/nodekit_configure.md @@ -25,5 +25,6 @@ Note: This is still a work in progress. Expect bugs and rough edges. * [nodekit](/README.md) - Manage Algorand nodes from the command line * [nodekit configure service](/man/nodekit_configure_service.md) - Install service files for the Algorand daemon. +* [nodekit configure telemetry](/man/nodekit_configure_telemetry.md) - Configure telemetry for the Algorand daemon -###### Auto generated by spf13/cobra on 7-Jan-2025 +###### Auto generated by spf13/cobra on 16-Jan-2025 diff --git a/man/nodekit_configure_telemetry.md b/man/nodekit_configure_telemetry.md new file mode 100644 index 00000000..07625c6c --- /dev/null +++ b/man/nodekit_configure_telemetry.md @@ -0,0 +1,38 @@ +## nodekit configure telemetry + +Configure telemetry for the Algorand daemon + +### Synopsis + + +Terminal Render + + +Configure telemetry for the Algorand daemon + +Overview: +When a node is run using the algod command, before the script starts the server, +it configures its telemetry based on the appropriate logging.config file. +When a node’s telemetry is enabled, a telemetry state is added to the node’s logger +reflecting the fields contained within the appropriate config file + +The default telemetry provider is Nodely. + +``` +nodekit configure telemetry [flags] +``` + +### Options + +``` + -d, --datadir string Data directory for the node + -e, --endpoint string Sets the "URI" property (default "https://tel.4160.nodely.io") + -h, --help help for telemetry + -n, --name string Enable Algorand remote logging with specified node name (default "anon") +``` + +### SEE ALSO + +* [nodekit configure](/man/nodekit_configure.md) - Change settings on the system (WIP) + +###### Auto generated by spf13/cobra on 16-Jan-2025