Skip to content

Commit 6c8702d

Browse files
authored
feat: influxdb v3 support (#6139)
1 parent d616a1d commit 6c8702d

54 files changed

Lines changed: 5116 additions & 604 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [unreleased]
22

3+
### Features
4+
5+
1. [#6139](https://github.com/influxdata/chronograf/pull/6139): Add support for InfluxDB V3
6+
37
### Other
48

59
1. [#6150](https://github.com/influxdata/chronograf/pull/6150): Upgrade golang to 1.25.3

V3TODO.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# InfluxDB v3 support TODOs
2+
3+
## Features
4+
5+
- [X] Support InfluxDB 3 Serverless
6+
- [X] UI should have old UI look for default
7+
- [X] Enable new UI look from settings
8+
9+
## Issues
10+
11+
- [X] List databases for Core in Explorer shows fewer dbs than with `show databases` manually
12+
- [X] Command line help print-out wrongly formated due to new v3 option:
13+
```
14+
/influxdb-type:choice[influx|influx-enterprise|influx-relay|influx-v2|influx-v3-core|influx-v3-enterprise|influx-v3-cloud-dedicated]
15+
```
16+
17+
## Tests
18+
19+
- [X] Unit test for Update Source for cloud dedicated fields
20+
- [X] Unit test for New Source for cloud dedicate fields
21+
- [X] Unit test for Client cloud dedicated fields
22+
- [ ] Unit test for query specific cloud dedicated fields
23+
- [ ] After finalizing UI, fix Cypress tests
24+
25+
## Polishing
26+
- [ ] Handle TODOs in code
27+
- [ ] Once all 5 v3 influxdb types are supported reorganize/refactor the code (cloud_dedicated.go, influx.go) to group similar server types
28+
29+
## Enhancements
30+
- [ ] UI: Better form validation to show errored field(s)
31+
- [ ] UI: distinguish optional fields

chronograf.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010
"time"
1111

12+
"github.com/influxdata/influxdb/influxql"
1213
"github.com/influxdata/kapacitor/client/v1"
1314
)
1415

@@ -27,7 +28,6 @@ const (
2728
ErrSourceInvalid = Error("source is invalid")
2829
ErrServerInvalid = Error("server is invalid")
2930
ErrAlertNotFound = Error("alert not found")
30-
ErrAuthentication = Error("user not authenticated")
3131
ErrUninitialized = Error("client uninitialized. Call Open() method")
3232
ErrInvalidAxis = Error("Unexpected axis in cell. Valid axes are 'x', 'y', and 'y2'")
3333
ErrInvalidColorType = Error("Invalid color type. Valid color types are 'min', 'max', 'threshold', 'text', and 'background'")
@@ -42,9 +42,6 @@ const (
4242
ErrCannotDeleteDefaultOrganization = Error("cannot delete default organization")
4343
ErrConfigNotFound = Error("cannot find configuration")
4444
ErrAnnotationNotFound = Error("annotation not found")
45-
ErrInvalidCellOptionsText = Error("invalid text wrapping option. Valid wrappings are 'truncate', 'wrap', and 'single line'")
46-
ErrInvalidCellOptionsSort = Error("cell options sortby cannot be empty'")
47-
ErrInvalidCellOptionsColumns = Error("cell options columns cannot be empty'")
4845
ErrOrganizationConfigNotFound = Error("could not find organization config")
4946
ErrInvalidCellQueryType = Error("invalid cell query type: must be 'flux' or 'influxql'")
5047
)
@@ -91,16 +88,43 @@ type Assets interface {
9188

9289
// Supported time-series databases
9390
const (
94-
// InfluxDB is the open-source time-series database
95-
InfluxDB = "influx"
96-
// InfluxEnteprise is the clustered HA time-series database
97-
InfluxEnterprise = "influx-enterprise"
98-
// InfluxRelay is the basic HA layer over InfluxDB
99-
InfluxRelay = "influx-relay"
91+
// InfluxDBv1 is InfluxDB OSS v1
92+
InfluxDBv1 = "influx"
93+
// InfluxDBv1Enterprise is InfluxDB v1 Enterprise (the clustered HA time-series database)
94+
InfluxDBv1Enterprise = "influx-enterprise"
95+
// InfluxDBv1Relay is the basic HA layer over InfluxDB v1
96+
InfluxDBv1Relay = "influx-relay"
97+
10098
// InfluxDBv2 is Influx DB 2.x with Token authentication
10199
InfluxDBv2 = "influx-v2"
100+
101+
// InfluxDBv3Core is InfluxDB 3 Core (self-managed)
102+
InfluxDBv3Core = "influx-v3-core"
103+
// InfluxDBv3Enterprise is InfluxDB 3 Enterprise (self-managed)
104+
InfluxDBv3Enterprise = "influx-v3-enterprise"
105+
// InfluxDBv3Clustered is InfluxDB Clustered (self-managed)
106+
InfluxDBv3Clustered = "influx-v3-clustered"
107+
// InfluxDBv3CloudDedicated is InfluxDB Cloud Dedicated (fully-managed)
108+
InfluxDBv3CloudDedicated = "influx-v3-cloud-dedicated"
109+
// InfluxDBv3Serverless is InfluxDB Cloud Serverless (fully-managed)
110+
InfluxDBv3Serverless = "influx-v3-serverless"
102111
)
103112

113+
func IsV3SrcType(srcType string) bool {
114+
return srcType == InfluxDBv3Core ||
115+
srcType == InfluxDBv3Enterprise ||
116+
srcType == InfluxDBv3Clustered ||
117+
srcType == InfluxDBv3CloudDedicated ||
118+
srcType == InfluxDBv3Serverless
119+
}
120+
121+
type V3Config struct {
122+
CloudDedicatedManagementURL string
123+
ClusteredAccountID string
124+
ClusteredClusterID string
125+
TimeConditionExpr influxql.Expr // Parsed time condition for SHOW TAG VALUES queries
126+
}
127+
104128
// TSDBStatus represents the current status of a time series database
105129
type TSDBStatus interface {
106130
// Connect will connect to the time series using the information in `Source`.
@@ -243,6 +267,11 @@ type Source struct {
243267
Username string `json:"username,omitempty"` // Username is the username to connect to the source
244268
Password string `json:"password,omitempty"` // Password is in CLEARTEXT
245269
SharedSecret string `json:"sharedSecret,omitempty"` // ShareSecret is the optional signing secret for Influx JWT authorization
270+
ClusterID string `json:"clusterId,omitempty"` // ClusterID is the cluster ID for InfluxDB Cloud Dedicated sources
271+
AccountID string `json:"accountId,omitempty"` // AccountID is the account ID for InfluxDB Cloud Dedicated sources
272+
ManagementToken string `json:"managementToken,omitempty"` // ManagementToken is the management token for InfluxDB Cloud Dedicated sources
273+
DatabaseToken string `json:"databaseToken,omitempty"` // DatabaseToken is the database token for InfluxDB Cloud Dedicated or other InfluxDB 3 sources
274+
TagsCSVPath string `json:"tagsCSVPath,omitempty"` // TagsCSVPath is the path to a directory containing CSV files (per db) with tags for InfluxDB Cloud Dedicated sources
246275
URL string `json:"url"` // URL are the connections to the source
247276
MetaURL string `json:"metaUrl,omitempty"` // MetaURL is the url for the meta node
248277
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` // InsecureSkipVerify as true means any certificate presented by the source is accepted.
@@ -251,6 +280,7 @@ type Source struct {
251280
Organization string `json:"organization"` // Organization is the organization ID that resource belongs to
252281
Role string `json:"role,omitempty"` // Not Currently Used. Role is the name of the minimum role that a user must possess to access the resource.
253282
DefaultRP string `json:"defaultRP"` // DefaultRP is the default retention policy used in database queries to this source
283+
DefaultDB string `json:"defaultDB,omitempty"` // DefaultDB is the default database used in queries for InfluxDB Cloud Dedicated when database list is not available
254284
Version string `json:"version,omitempty"` // Version of influxdb
255285
}
256286

@@ -971,6 +1001,7 @@ type Environment struct {
9711001
TelegrafSystemInterval time.Duration `json:"telegrafSystemInterval"`
9721002
HostPageDisabled bool `json:"HostPageDisabled"`
9731003
CustomAutoRefresh string `json:"customAutoRefresh,omitempty"`
1004+
V3SupportEnabled bool `json:"v3SupportEnabled"`
9741005
}
9751006

9761007
// KVClient defines what each kv store should be capable of.

cmd/chronograf/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ func main() {
4343

4444
if _, err := parser.Parse(); err != nil {
4545
code := 1
46-
if fe, ok := err.(*flags.Error); ok {
47-
if fe.Type == flags.ErrHelp {
48-
code = 0
49-
}
46+
if fe, ok := err.(*flags.Error); ok && fe.Type == flags.ErrHelp {
47+
code = 0
48+
}
49+
if code != 0 {
50+
fmt.Printf("Error: %s\n", err)
5051
}
5152
os.Exit(code)
5253
}

influx/authorization.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ func (n *NoAuthorization) Set(req *http.Request) error { return nil }
2323

2424
// DefaultAuthorization creates either a shared JWT builder, basic auth or Noop or Token authentication
2525
func DefaultAuthorization(src *chronograf.Source) Authorizer {
26+
// Use Token authentication for InfluxDB v3 Serverless
27+
if src.Type == chronograf.InfluxDBv3Serverless {
28+
return &TokenAuth{
29+
Token: src.DatabaseToken,
30+
}
31+
}
32+
// Use Bearer Token authentication for all other InfluxDB 3 types
33+
if chronograf.IsV3SrcType(src.Type) {
34+
return &BearerToken{
35+
Token: src.DatabaseToken,
36+
}
37+
}
2638
// Use Token authentication for InfluxDB v2
2739
if src.Type == chronograf.InfluxDBv2 {
2840
return &TokenAuth{
@@ -71,6 +83,16 @@ func (a *TokenAuth) Set(r *http.Request) error {
7183
return nil
7284
}
7385

86+
// BearerToken adds `Authorization: Bearer <Token>` to the request header, where the token is in non-JWT format.
87+
type BearerToken struct {
88+
Token string
89+
}
90+
91+
func (a *BearerToken) Set(r *http.Request) error {
92+
r.Header.Set("Authorization", "Bearer "+a.Token)
93+
return nil
94+
}
95+
7496
// BearerJWT is the default Bearer for InfluxDB
7597
type BearerJWT struct {
7698
Username string

0 commit comments

Comments
 (0)