-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6655 from influxdata/nc-http-subs
Add HTTP(s) Subscriptions
- Loading branch information
Showing
6 changed files
with
243 additions
and
88 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 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 |
---|---|---|
@@ -1,12 +1,35 @@ | ||
package subscriber | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/influxdata/influxdb/toml" | ||
) | ||
|
||
const ( | ||
DefaultHTTPTimeout = 30 * time.Second | ||
) | ||
|
||
// Config represents a configuration of the subscriber service. | ||
type Config struct { | ||
// Whether to enable to Subscriber service | ||
Enabled bool `toml:"enabled"` | ||
|
||
HTTPTimeout toml.Duration `toml:"http-timeout"` | ||
} | ||
|
||
// NewConfig returns a new instance of a subscriber config. | ||
func NewConfig() Config { | ||
return Config{Enabled: true} | ||
return Config{ | ||
Enabled: true, | ||
HTTPTimeout: toml.Duration(DefaultHTTPTimeout), | ||
} | ||
} | ||
|
||
func (c Config) Validate() error { | ||
if c.HTTPTimeout <= 0 { | ||
return errors.New("http-timeout must be greater than 0") | ||
} | ||
return nil | ||
} |
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,39 @@ | ||
package subscriber | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/influxdata/influxdb/client/v2" | ||
"github.com/influxdata/influxdb/coordinator" | ||
) | ||
|
||
// HTTP supports writing points over HTTP using the line protocol. | ||
type HTTP struct { | ||
c client.Client | ||
} | ||
|
||
// NewHTTP returns a new HTTP points writer with default options. | ||
func NewHTTP(addr string, timeout time.Duration) (*HTTP, error) { | ||
conf := client.HTTPConfig{ | ||
Addr: addr, | ||
Timeout: timeout, | ||
} | ||
c, err := client.NewHTTPClient(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &HTTP{c: c}, nil | ||
} | ||
|
||
// WritePoints writes points over HTTP transport. | ||
func (h *HTTP) WritePoints(p *coordinator.WritePointsRequest) (err error) { | ||
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{ | ||
Database: p.Database, | ||
RetentionPolicy: p.RetentionPolicy, | ||
}) | ||
for _, pt := range p.Points { | ||
bp.AddPoint(client.NewPointFrom(pt)) | ||
} | ||
err = h.c.Write(bp) | ||
return | ||
} |
Oops, something went wrong.