-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #108
- Loading branch information
Showing
23 changed files
with
760 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package configure | ||
|
||
import ( | ||
cmdutils "github.com/algorandfoundation/nodekit/cmd/utils" | ||
"github.com/algorandfoundation/nodekit/cmd/utils/explanations" | ||
"github.com/algorandfoundation/nodekit/internal/algod" | ||
"github.com/algorandfoundation/nodekit/internal/algod/telemetry" | ||
"github.com/algorandfoundation/nodekit/internal/algod/utils" | ||
"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 telemetryDisable bool | ||
var telemetryEnable bool | ||
|
||
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 = cmdutils.WithAlgodFlags(&cobra.Command{ | ||
Use: "telemetry", | ||
Short: telemetryShort, | ||
Long: telemetryLong, | ||
PersistentPreRunE: cmdutils.IsSudoCmd, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg)) | ||
resolvedDir, err := algod.GetDataDir(dataDir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Current Log Configuration | ||
logConfig, _ := utils.GetLogConfigFromDataDir(resolvedDir) | ||
|
||
hasDisable := cmd.Flags().Lookup("disable").Changed | ||
hasEnabled := cmd.Flags().Lookup("enable").Changed | ||
hasEndpoint := cmd.Flags().Lookup("endpoint").Changed | ||
hasName := cmd.Flags().Lookup("name").Changed | ||
|
||
hasFlags := hasDisable || hasEndpoint || hasName || hasEnabled | ||
|
||
if hasFlags { | ||
newConfig := telemetry.Config{ | ||
SendToLog: logConfig.SendToLog, | ||
GUID: logConfig.GUID, | ||
FilePath: logConfig.FilePath, | ||
UserName: logConfig.UserName, | ||
Password: logConfig.Password, | ||
MinLogLevel: logConfig.MinLogLevel, | ||
ReportHistoryLevel: logConfig.ReportHistoryLevel, | ||
} | ||
if hasEndpoint { | ||
newConfig.URI = telemetryEndpoint | ||
} else { | ||
newConfig.URI = logConfig.URI | ||
} | ||
if hasName { | ||
newConfig.Name = telemetryName | ||
} else { | ||
newConfig.Name = logConfig.Name | ||
} | ||
|
||
if hasDisable { | ||
newConfig.Enable = false | ||
} else if hasEnabled { | ||
newConfig.Enable = true | ||
} else { | ||
newConfig.Enable = logConfig.Enable | ||
} | ||
mergeConfig := telemetry.MergeLogConfigs(*logConfig, newConfig) | ||
if logConfig.IsEqual(mergeConfig) { | ||
log.Debug("Configuration up to date, nothing to do") | ||
} else { | ||
logConfig = &mergeConfig | ||
err := utils.WriteLogConfigToDataDir(resolvedDir, logConfig) | ||
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().BoolVarP(&telemetryDisable, "disable", "", false, "Disables telemetry") | ||
telemetryCmd.Flags().BoolVarP(&telemetryEnable, "enable", "", false, "Enables telemetry") | ||
telemetryCmd.MarkFlagsOneRequired("disable", "enable") | ||
telemetryCmd.MarkFlagsMutuallyExclusive("disable", "enable") | ||
telemetryCmd.Flags().StringVarP(&telemetryEndpoint, "endpoint", "e", string(cmdutils.NodelyTelemetryProvider), "Sets the \"URI\" property") | ||
telemetryCmd.Flags().StringVarP(&telemetryName, "name", "n", "anon", "Enable Algorand remote logging with specified node name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package disable | ||
|
||
import ( | ||
"github.com/algorandfoundation/nodekit/cmd/utils/explanations" | ||
"github.com/algorandfoundation/nodekit/ui/style" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Short = "Disable Telemetry" | ||
var Long = lipgloss.JoinVertical( | ||
lipgloss.Left, | ||
style.Purple(style.BANNER), | ||
"", | ||
style.Bold(Short), | ||
"", | ||
style.BoldUnderline("Overview:"), | ||
"Configure telemetry for the Algorand daemon.", | ||
"", | ||
style.Yellow.Render(explanations.ExperimentalWarning), | ||
) | ||
var Cmd = &cobra.Command{ | ||
Use: "disable", | ||
Short: Short, | ||
Long: Long, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(nodelyCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package disable | ||
|
||
import ( | ||
"errors" | ||
cmdutils "github.com/algorandfoundation/nodekit/cmd/utils" | ||
"github.com/algorandfoundation/nodekit/cmd/utils/explanations" | ||
"github.com/algorandfoundation/nodekit/internal/algod" | ||
"github.com/algorandfoundation/nodekit/internal/algod/utils" | ||
"github.com/algorandfoundation/nodekit/internal/system" | ||
"github.com/algorandfoundation/nodekit/ui/style" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/log" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var nodelyShort = "Disable Nodely" | ||
var nodelyLong = lipgloss.JoinVertical( | ||
lipgloss.Left, | ||
style.Purple(style.BANNER), | ||
"", | ||
style.Bold(nodelyShort), | ||
"", | ||
style.BoldUnderline("Overview:"), | ||
"Nodely Telemetry is a free telemetry service offered by a third party (Nodely)", | ||
"Enabling telemetry will configure your node to send health metrics to Nodely", | ||
"Privacy note: Information about your node (including participating accounts and approximate geographic location) will be associated with an anonymous user identifier (GUID.)", | ||
"Tip: Keep this GUID identifier private if you do not want this information to be linked to your identity.", | ||
"", | ||
style.Yellow.Render(explanations.ExperimentalWarning), | ||
) | ||
|
||
var dataDir string | ||
|
||
const ( | ||
NodelyNotConfiguredErrorMsg = "nodely is not configured" | ||
NodelyDisabledErrorMsg = "nodely is already disabled" | ||
) | ||
|
||
var nodelyQuestion = ` | ||
# Overview | ||
Nodely Telemetry is a free telemetry service offered by a third party (Nodely) | ||
Enabling telemetry will configure your node to send health metrics to Nodely | ||
> Privacy note: Information about your node (including participating accounts and approximate geographic location) will be associated with an anonymous user identifier (GUID.) | ||
> Tip: Keep this GUID identifier private if you do not want this information to be linked to your identity. | ||
**Do you want to disable telemetry with the nodely provider? (y/n)** | ||
` | ||
|
||
var nodelyCmd = cmdutils.WithAlgodFlags(&cobra.Command{ | ||
Use: "nodely", | ||
Short: nodelyShort, | ||
Long: nodelyLong, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Warn(explanations.SudoWarningMsg) | ||
|
||
// Resolve Data Directory | ||
dataDir, err := algod.GetDataDir(dataDir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Fetch configuration | ||
config, err := utils.GetLogConfigFromDataDir(dataDir) | ||
cobra.CheckErr(err) | ||
|
||
// Error if already disabled | ||
if !config.Enable && config.URI == string(cmdutils.NodelyTelemetryProvider) { | ||
log.Fatal(errors.New(NodelyDisabledErrorMsg)) | ||
} | ||
cmd.Println(style.BANNER) | ||
|
||
answer := cmdutils.Prompt(nodelyQuestion) | ||
if answer { | ||
// Get the path to nodekit | ||
path, err := os.Executable() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Elevated Configuration | ||
err = system.RunAll(system.CmdsList{{"sudo", path, "configure", "telemetry", "--disable"}}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
}, | ||
}, &dataDir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package enable | ||
|
||
import ( | ||
"github.com/algorandfoundation/nodekit/cmd/utils/explanations" | ||
"github.com/algorandfoundation/nodekit/ui/style" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Short = "Enable Telemetry" | ||
var Long = lipgloss.JoinVertical( | ||
lipgloss.Left, | ||
style.Purple(style.BANNER), | ||
"", | ||
style.Bold(Short), | ||
"", | ||
style.BoldUnderline("Overview:"), | ||
"Configure telemetry for the Algorand daemon.", | ||
"", | ||
style.Yellow.Render(explanations.ExperimentalWarning), | ||
) | ||
var Cmd = &cobra.Command{ | ||
Use: "enable", | ||
Short: Short, | ||
Long: Long, | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(nodelyCmd) | ||
} |
Oops, something went wrong.