Skip to content
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

Allow setting the node id in the influx cli program #9184

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [#9181](https://github.com/influxdata/influxdb/pull/9181): Schedule a full compaction after a successful import
- [#9218](https://github.com/influxdata/influxdb/pull/9218): Add Prometheus `/metrics` endpoint.
- [#9213](https://github.com/influxdata/influxdb/pull/9213): Add ability to generate shard digests.
- [#9184](https://github.com/influxdata/influxdb/pull/9184): Allow setting the node id in the influx cli program.

### Bugfixes

Expand Down
12 changes: 12 additions & 0 deletions client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ type Query struct {
//
// Chunked must be set to true for this option to be used.
ChunkSize int

// NodeID sets the data node to use for the query results. This option only
// has any effect in the enterprise version of the software where there can be
// more than one data node and is primarily useful for analyzing differences in
// data. The default behavior is to automatically select the appropriate data
// nodes to retrieve all of the data. On a database where the number of data nodes
// is greater than the replication factor, it is expected that setting this option
// will only retrieve partial data.
NodeID int
}

// ParseConnectionString will parse a string to create a valid connection URL
Expand Down Expand Up @@ -198,6 +207,9 @@ func (c *Client) QueryContext(ctx context.Context, q Query) (*Response, error) {
values.Set("chunk_size", strconv.Itoa(q.ChunkSize))
}
}
if q.NodeID > 0 {
values.Set("node_id", strconv.Itoa(q.NodeID))
}
if c.precision != "" {
values.Set("epoch", c.precision)
}
Expand Down
24 changes: 24 additions & 0 deletions cmd/influx/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type CommandLine struct {
Import bool
Chunked bool
ChunkSize int
NodeID int
Quit chan struct{}
IgnoreSignals bool // Ignore signals normally caught by this process (used primarily for testing)
ForceTTY bool // Force the CLI to act as if it were connected to a TTY
Expand Down Expand Up @@ -284,6 +285,8 @@ func (c *CommandLine) ParseCommand(cmd string) error {
}
case "use":
c.use(cmd)
case "node":
c.node(cmd)
case "insert":
return c.Insert(cmd)
case "clear":
Expand Down Expand Up @@ -513,6 +516,26 @@ func (c *CommandLine) retentionPolicyExists(db, rp string) bool {
return true
}

func (c *CommandLine) node(cmd string) {
args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ")
if len(args) != 2 {
fmt.Println("Improper number of arguments for 'node' command, requires exactly one.")
return
}

if args[1] == "clear" {
c.NodeID = 0
return
}

id, err := strconv.Atoi(args[1])
if err != nil {
fmt.Printf("Unable to parse node id from %s. Must be an integer or 'clear'.\n", args[1])
return
}
c.NodeID = id
}

// SetChunkSize sets the chunk size
// 0 sets it back to the default
func (c *CommandLine) SetChunkSize(cmd string) {
Expand Down Expand Up @@ -711,6 +734,7 @@ func (c *CommandLine) query(query string) client.Query {
Database: c.Database,
Chunked: c.Chunked,
ChunkSize: c.ChunkSize,
NodeID: c.NodeID,
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func main() {
fs.StringVar(&c.ClientConfig.Precision, "precision", defaultPrecision, "Precision specifies the format of the timestamp: rfc3339,h,m,s,ms,u or ns.")
fs.StringVar(&c.ClientConfig.WriteConsistency, "consistency", "all", "Set write consistency level: any, one, quorum, or all.")
fs.BoolVar(&c.Pretty, "pretty", false, "Turns on pretty print for the json format.")
fs.IntVar(&c.NodeID, "node", 0, "Specify the node that data should be retrieved from (enterprise only).")
fs.StringVar(&c.Execute, "execute", c.Execute, "Execute command and quit.")
fs.BoolVar(&c.ShowVersion, "version", false, "Displays the InfluxDB version.")
fs.BoolVar(&c.Import, "import", false, "Import a previous database.")
Expand Down
3 changes: 3 additions & 0 deletions man/influx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ OPTIONS
-pretty::
Turns on pretty print format for the JSON format.

-node <n>::
Specifies the data node that should be queried for data. This option is only valid on enterprise clusters.

-import::
Import a previous database export from a file. If specified, '-path <path>' must also be specified.

Expand Down