Skip to content

Commit

Permalink
Merge branch 'master' into lh/onboard-optional-password
Browse files Browse the repository at this point in the history
  • Loading branch information
lyondhill authored Aug 5, 2020
2 parents 295d689 + fe5e579 commit 432d34c
Show file tree
Hide file tree
Showing 91 changed files with 3,687 additions and 535 deletions.
21 changes: 11 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ commands:
steps:
- run:
name: Install clang
command: sudo apt-get install -y --no-install-recommends clang musl-tools
command: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang musl-tools
- run:
name: Install rust compiler
command: |
Expand All @@ -22,13 +22,13 @@ commands:
- run:
name: Install linux cross compilers
command: >
sudo apt-get install -y --no-install-recommends
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
gcc-aarch64-linux-gnu libc6-dev-arm64-cross
sudo apt-get update && sudo apt-get install -y --no-install-recommends
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
gcc-aarch64-linux-gnu libc6-dev-arm64-cross
- run:
name: Install macOS cross compilers
command: |
sudo apt-get install -y --no-install-recommends \
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
cmake patch libxml2-dev libssl-dev zlib1g-dev
sudo mkdir -p /opt/osxcross
cd /opt
Expand Down Expand Up @@ -143,6 +143,7 @@ jobs:
name: Restoring GOPATH/pkg/mod
keys:
- influxdb-gomod-{{ checksum "go.sum" }} # Just match the go.sum checksum cache.
- run: sudo apt-get update
- run: sudo apt-get install -y netcat-openbsd
- run: sudo apt-get install -y bzr
- install_rust_compiler
Expand Down Expand Up @@ -289,7 +290,7 @@ jobs:
name: Restoring GOPATH/pkg/mod
keys:
- influxdb-gomod-{{ checksum "go.sum" }} # Matches based on go.sum checksum.
- run: sudo apt-get install -y bzr
- run: sudo apt-get update && sudo apt-get install -y bzr
- install_rust_compiler
- run: mkdir -p $TEST_RESULTS
- run: make test-go # This uses the test cache so it may succeed or fail quickly.
Expand Down Expand Up @@ -340,7 +341,7 @@ jobs:
working_directory: /go/src/github.com/influxdata/influxdb
steps:
- checkout
- run: sudo apt-get install -y bzr
- run: sudo apt-get update && sudo apt-get install -y bzr
- install_rust_compiler
- run: mkdir -p $TEST_RESULTS
- run: |
Expand Down Expand Up @@ -373,7 +374,7 @@ jobs:
working_directory: /go/src/github.com/influxdata/influxdb
steps:
- checkout
- run: sudo apt-get install -y bzr
- run: sudo apt-get update && sudo apt-get install -y bzr
- install_rust_compiler
- run: make checkcommit

Expand Down Expand Up @@ -419,7 +420,7 @@ jobs:
- run:
name: "Docker Login"
command: docker login -u "$QUAY_USER" -p $QUAY_PASS quay.io
- run: sudo apt-get install -y bzr
- run: sudo apt-get update && sudo apt-get install -y bzr
- install_rust_compiler
- install_release_tools
- run: make protoc # installs protoc
Expand Down Expand Up @@ -456,7 +457,7 @@ jobs:
- run:
name: "Docker Login"
command: docker login -u "$QUAY_USER" -p $QUAY_PASS quay.io
- run: sudo apt-get install -y bzr
- run: sudo apt-get update && sudo apt-get install -y bzr
- install_rust_compiler
- install_release_tools
- run: make protoc # installs protoc
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
1. [19075](https://github.com/influxdata/influxdb/pull/19075): Add resource links to a stack's resources from public HTTP API list/read calls
1. [19103](https://github.com/influxdata/influxdb/pull/19103): Enhance resource creation experience when limits are reached
1. [19225](https://github.com/influxdata/influxdb/pull/19225): Allow user onboarding to optionally set passwords
1. [19223](https://github.com/influxdata/influxdb/pull/19223): Add dashboards command to influx CLI

### Bug Fixes

1. [19043](https://github.com/influxdata/influxdb/pull/19043): Enforce all influx CLI flag args are valid
1. [19188](https://github.com/influxdata/influxdb/pull/19188): Dashboard cells correctly map results when multiple queries exist
1. [19146](https://github.com/influxdata/influxdb/pull/19146): Dashboard cells and overlay use UTC as query time when toggling to UTC timezone

## v2.0.0-beta.15 [2020-07-23]

Expand Down
154 changes: 154 additions & 0 deletions cmd/influx/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package main

import (
"context"

"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/cmd/influx/internal"
"github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/tenant"
"github.com/spf13/cobra"
)

func cmdDashboard(f *globalFlags, opts genericCLIOpts) *cobra.Command {
return newCmdDashboardBuilder(newDashboardSVCs, f, opts).cmdDashboards()
}

type dashboardSVCsFn func() (influxdb.DashboardService, influxdb.OrganizationService, error)

type cmdDashboardBuilder struct {
genericCLIOpts
*globalFlags

svcFn dashboardSVCsFn

ids []string
org organization
}

func newCmdDashboardBuilder(svcFn dashboardSVCsFn, f *globalFlags, opts genericCLIOpts) *cmdDashboardBuilder {
return &cmdDashboardBuilder{
genericCLIOpts: opts,
globalFlags: f,
svcFn: svcFn,
}
}

func (b *cmdDashboardBuilder) cmdDashboards() *cobra.Command {
cmd := b.newCmd("dashboards", b.listRunE)
cmd.Short = "List Dashboard(s)."
cmd.Long = `
List Dashboard(s).
Examples:
# list all known Dashboards
influx dashboards
# list all known Dashboards matching ids
influx dashboards --id $ID1 --id $ID2
# list all known Dashboards matching ids shorts
influx dashboards -i $ID1 -i $ID2
`

b.org.register(cmd, false)
cmd.Flags().StringArrayVarP(&b.ids, "id", "i", nil, "Dashboard ID to retrieve.")

return cmd
}

func (b *cmdDashboardBuilder) listRunE(cmd *cobra.Command, args []string) error {
svc, orgSVC, err := b.svcFn()
if err != nil {
return err
}

orgID, _ := b.org.getID(orgSVC)
if orgID == 0 && len(b.ids) == 0 {
return &influxdb.Error{
Code: influxdb.EUnprocessableEntity,
Msg: "at least one of org, org-id, or id must be provided",
}
}

var ids []*influxdb.ID
for _, rawID := range b.ids {
id, err := influxdb.IDFromString(rawID)
if err != nil {
return err
}
ids = append(ids, id)
}

var (
out []*influxdb.Dashboard
offset int
)
const limit = 100
for {
dashboards, _, err := svc.FindDashboards(context.Background(), influxdb.DashboardFilter{
IDs: ids,
OrganizationID: &orgID,
}, influxdb.FindOptions{
Limit: limit,
Offset: offset,
})
if err != nil && influxdb.ErrorCode(err) != influxdb.ENotFound {
return err
}
out = append(out, dashboards...)
if len(dashboards) < limit {
break
}
offset += len(dashboards)
}

return b.writeDashboards(out...)
}

func (b *cmdDashboardBuilder) writeDashboards(dashboards ...*influxdb.Dashboard) error {
if b.json {
return b.writeJSON(dashboards)
}

tabW := b.newTabWriter()
defer tabW.Flush()

writeDashboardRows(tabW, dashboards...)
return nil
}

func writeDashboardRows(tabW *internal.TabWriter, dashboards ...*influxdb.Dashboard) {
tabW.WriteHeaders("ID", "OrgID", "Name", "Description", "Num Cells")
for _, d := range dashboards {
tabW.Write(map[string]interface{}{
"ID": d.ID,
"OrgID": d.OrganizationID.String(),
"Name": d.Name,
"Description": d.Description,
"Num Cells": len(d.Cells),
})
}
}

func (b *cmdDashboardBuilder) newCmd(use string, runE func(*cobra.Command, []string) error) *cobra.Command {
cmd := b.genericCLIOpts.newCmd(use, runE, true)
b.genericCLIOpts.registerPrintOptions(cmd)
b.globalFlags.registerFlags(cmd)
return cmd
}

func newDashboardSVCs() (influxdb.DashboardService, influxdb.OrganizationService, error) {
httpClient, err := newHTTPClient()
if err != nil {
return nil, nil, err
}

orgSVC := &tenant.OrgClientService{
Client: httpClient,
}
dashSVC := &http.DashboardService{
Client: httpClient,
}
return dashSVC, orgSVC, nil
}
1 change: 1 addition & 0 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func influxCmd(opts ...genericCLIOptFn) *cobra.Command {
cmdBackup,
cmdBucket,
cmdConfig,
cmdDashboard,
cmdDelete,
cmdExport,
cmdOrganization,
Expand Down
2 changes: 1 addition & 1 deletion cmd/influx/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func writeTelegrafRows(tabW *internal.TabWriter, cfgs ...*influxdb.TelegrafConfi
for _, cfg := range cfgs {
tabW.Write(map[string]interface{}{
"ID": cfg.ID,
"OrgID": cfg.OrgID,
"OrgID": cfg.OrgID.String(),
"Name": cfg.Name,
"Description": cfg.Description,
})
Expand Down
Loading

0 comments on commit 432d34c

Please sign in to comment.