-
Notifications
You must be signed in to change notification settings - Fork 20
Add -local_only flag to get local node metrics per node #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
f66a901
7b8e5f0
8ca0752
b04276a
4f5f8bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ type argumentList struct { | |
| IndicesRegex string `default:"" help:"A regex pattern that matches the index names to collect. Collects all if unspecified"` | ||
| ShowVersion bool `default:"false" help:"Print build information and exit"` | ||
| MasterOnly bool `default:"false" help:"Collect cluster metrics on the elected master only"` | ||
| LocalOnly bool `default:"false" help:"Collect node metrics on the local node only"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add an integration test?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need help with this |
||
| TLSInsecureSkipVerify bool `default:"false" help:"Enabled TLS insecure skip verify"` | ||
| } | ||
|
|
||
|
|
@@ -61,6 +62,9 @@ func main() { | |
| buildDate) | ||
| os.Exit(0) | ||
| } | ||
| if args.MasterOnly && args.LocalOnly { | ||
| logErrorAndExit(fmt.Errorf("Select argument -master_only or -local_only, not both")) | ||
| } | ||
|
|
||
| // Create a client for metrics | ||
| metricsClient, err := NewClient(args.Hostname) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,34 +18,41 @@ var ( | |
|
|
||
| // populateMetrics wrapper to call each of the individual populate functions | ||
| func populateMetrics(i *integration.Integration, client Client, env string) { | ||
| if args.MasterOnly { | ||
| nodeID, err := getLocalNodeID(client) | ||
| nodeID, clusterName, err := getLocalNodeID(client) | ||
TeonLucas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| log.Error("There was an error gathering the host node ID: %v", err) | ||
| return | ||
| } | ||
|
|
||
| if args.LocalOnly { | ||
| err = populateNodesMetrics(i, client, clusterName, localNodeStatsEndpoint) | ||
| if err != nil { | ||
| log.Error("There was an error gathering the host node ID: %v", err) | ||
| return | ||
| log.Error("There was an error populating metrics for local node: %v", err) | ||
| } | ||
| masterID, err := getMasterNodeID(client) | ||
| if err != nil { | ||
| log.Error("There was an error gathering the elected master node ID: %v", err) | ||
| return | ||
| } | ||
| if nodeID != masterID { | ||
| if !getClusterNeeded(client, nodeID) { | ||
| log.Info("The host is not the elected master, cluster metrics will be skipped") | ||
| return | ||
| } | ||
| log.Info("The host is the elected master, cluster metrics will be collected") | ||
TeonLucas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| if args.MasterOnly { | ||
| if !getClusterNeeded(client, nodeID) { | ||
| log.Info("The host is not the elected master, node/cluster metrics will be skipped") | ||
| return | ||
| } | ||
| log.Info("The host is the elected master, node/cluster metrics will be collected") | ||
| } | ||
| err = populateNodesMetrics(i, client, clusterName, nodeStatsEndpoint) | ||
| if err != nil { | ||
| log.Error("There was an error populating metrics for nodes: %v", err) | ||
| } | ||
| } | ||
|
|
||
| clusterName, err := populateClusterMetrics(i, client, env) | ||
| _, err = populateClusterMetrics(i, client, env) | ||
| if err != nil { | ||
| log.Error("There was an error populating metrics for clusters: %v", err) | ||
| } | ||
|
|
||
| err = populateNodesMetrics(i, client, clusterName) | ||
| if err != nil { | ||
| log.Error("There was an error populating metrics for nodes: %v", err) | ||
| } | ||
|
|
||
| // we want to use the response from common to populate some index-specific stats. | ||
| commonResponse, err := populateCommonMetrics(i, client, clusterName) | ||
| if err != nil { | ||
|
|
@@ -60,23 +67,38 @@ func populateMetrics(i *integration.Integration, client Client, env string) { | |
| } | ||
| } | ||
|
|
||
| func getLocalNodeID(client Client) (nodeId string, err error) { | ||
| // getClusterNeeded determines if cluster and common metrics should be scraped | ||
| func getClusterNeeded(client Client, nodeID string) (needed bool) { | ||
| if args.MasterOnly || args.LocalOnly { | ||
| masterID, err := getMasterNodeID(client) | ||
| if err != nil { | ||
| log.Error("There was an error gathering the elected master node ID: %v", err) | ||
|
||
| return | ||
| } | ||
| needed = nodeID == masterID | ||
|
||
| } else { | ||
| needed = true | ||
| } | ||
| return | ||
|
||
| } | ||
|
|
||
| func getLocalNodeID(client Client) (nodeId, clusterName string, err error) { | ||
| var nodeResponseObject LocalNodeResponse | ||
| err = client.Request(localNodeInventoryEndpoint, &nodeResponseObject) | ||
| err = client.Request(localNodeIdEndpoint, &nodeResponseObject) | ||
| if err != nil { | ||
| return "", err | ||
| return "", "", err | ||
| } | ||
| return parseLocalNodeID(nodeResponseObject) | ||
| } | ||
|
|
||
| func parseLocalNodeID(nodeStats LocalNodeResponse) (string, error) { | ||
| func parseLocalNodeID(nodeStats LocalNodeResponse) (nodeId, clusterName string, err error) { | ||
| nodes := nodeStats.Nodes | ||
| if len(nodes) == 1 { | ||
| for k := range nodes { | ||
| return k, nil | ||
| return k, nodeStats.ClusterName, nil | ||
| } | ||
| } | ||
| return "", errLocalNodeID | ||
| return "", "", errLocalNodeID | ||
| } | ||
|
|
||
| func getMasterNodeID(client Client) (masterId string, err error) { | ||
|
|
@@ -91,10 +113,10 @@ func getMasterNodeID(client Client) (masterId string, err error) { | |
| return masterIdResponseObject[0].ID, nil | ||
| } | ||
|
|
||
| func populateNodesMetrics(i *integration.Integration, client Client, clusterName string) error { | ||
| func populateNodesMetrics(i *integration.Integration, client Client, clusterName, endpoint string) error { | ||
| log.Info("Collecting node metrics") | ||
| nodeResponse := new(NodeResponse) | ||
| err := client.Request(nodeStatsEndpoint, &nodeResponse) | ||
| err := client.Request(endpoint, &nodeResponse) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need help updating mock
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated integration tests so that it passes now |
Uh oh!
There was an error while loading. Please reload this page.