Documentation
¶
Index ¶
- type Client
- func (c *Client) CloseStream(ctx context.Context) (*gpb.AffectedRows, error)
- func (c *Client) Delete(ctx context.Context, tables ...*table.Table) (*gpb.GreptimeResponse, error)
- func (c *Client) DeleteObject(ctx context.Context, obj any) (*gpb.GreptimeResponse, error)
- func (c *Client) HealthCheck(ctx context.Context) (*gpb.HealthCheckResponse, error)
- func (c *Client) StreamDelete(ctx context.Context, tables ...*table.Table) error
- func (c *Client) StreamDeleteObject(ctx context.Context, body any) error
- func (c *Client) StreamWrite(ctx context.Context, tables ...*table.Table) error
- func (c *Client) StreamWriteObject(ctx context.Context, body any) error
- func (c *Client) Write(ctx context.Context, tables ...*table.Table) (*gpb.GreptimeResponse, error)
- func (c *Client) WriteObject(ctx context.Context, obj any) (*gpb.GreptimeResponse, error)
- type Config
- func (c *Config) WithAuth(username, password string) *Config
- func (c *Config) WithDatabase(database string) *Config
- func (c *Config) WithDialOption(opt grpc.DialOption) *Config
- func (c *Config) WithInsecure(insecure bool) *Config
- func (c *Config) WithKeepalive(time, timeout time.Duration) *Config
- func (c *Config) WithMeterProvider(p metric.MeterProvider) *Config
- func (c *Config) WithMetricsEnabled(b bool) *Config
- func (c *Config) WithPort(port int) *Config
- func (c *Config) WithTraceProvider(p trace.TracerProvider) *Config
- func (c *Config) WithTracesEnabled(b bool) *Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.2.0
type Client struct {
// contains filtered or unexported fields
}
Client helps to write data into GreptimeDB. A Client is safe for concurrent use by multiple goroutines,you can have one Client instance in your application.
func NewClient ¶ added in v0.2.0
NewClient helps to create the greptimedb client, which will be responsible write data into GreptimeDB.
func (*Client) CloseStream ¶ added in v0.2.0
CloseStream closes the stream. Once we’ve finished writing our client’s requests to the stream using client.StreamWrite or client.StreamWriteObject, we need to call client.CloseStream to let GreptimeDB know that we’ve finished writing and are expecting to receive a response.
func (*Client) Delete ¶ added in v0.5.0
Delete is to delete the data from GreptimeDB via explicit schema.
tbl, err := table.New(<tableName>) // add column at first. This is to define the schema of the table. tbl.AddTagColumn("tag1", types.INT64) tbl.AddTimestampColumn("timestamp", types.TIMESTAMP_MILLISECOND) // you can add multiple row(s). This is the real data. tbl.AddRow("tag1", timestamp) // delete the data from GreptimeDB resp, err := client.Delete(context.Background() tbl)
func (*Client) DeleteObject ¶ added in v0.5.0
DeleteObject is like [Delete] to delete the data from GreptimeDB, but schema is defined in the struct tag. resp, err := client.DeleteObject(context.Background(), deleteMonitors)
func (*Client) HealthCheck ¶ added in v0.5.2
HealthCheck will check GreptimeDB health status.
func (*Client) StreamDelete ¶ added in v0.5.0
StreamDelete is to delete the data from GreptimeDB via explicit schema.
tbl, err := table.New(<tableName>) // add column at first. This is to define the schema of the table. tbl.AddTagColumn("tag1", types.INT64) tbl.AddTimestampColumn("timestamp", types.TIMESTAMP_MILLISECOND) // you can add multiple row(s). This is the real data. tbl.AddRow("tag1", timestamp) // delete the data from GreptimeDB resp, err := client.StreamDelete(context.Background(), tbl)
func (*Client) StreamDeleteObject ¶ added in v0.5.0
StreamDeleteObject is like [StreamDelete] to Delete the data from GreptimeDB, but schema is defined in the struct tag. resp, err := client.StreamDeleteObject(context.Background(), deleteMonitors)
func (*Client) StreamWrite ¶ added in v0.2.0
StreamWrite is to send the data into GreptimeDB via explicit schema.
tbl, err := table.New(<tableName>) // add column at first. This is to define the schema of the table. tbl.AddTagColumn("tag1", types.INT64) tbl.AddFieldColumn("field1", types.STRING) tbl.AddFieldColumn("field2", types.FLOAT64) tbl.AddTimestampColumn("timestamp", types.TIMESTAMP_MILLISECOND) timestamp = time.Now() // you can add multiple row(s). This is the real data. tbl.AddRow(1, "hello", 1.1, timestamp) // send data into GreptimeDB resp, err := client.StreamWrite(context.Background(), tbl)
func (*Client) StreamWriteObject ¶ added in v0.3.0
StreamWriteObject is like [StreamWrite] to send the data into GreptimeDB, but schema is defined in the struct tag.
type monitor struct { ID int64 `greptime:"tag;column:id;type:int64"` Host string `greptime:"tag;column:host;type:string"` Memory uint64 `greptime:"field;column:memory;type:uint64"` Cpu float64 `greptime:"field;column:cpu;type:float64"` Temperature int64 `greptime:"field;column:temperature;type:int64"` Running bool `greptime:"field;column:running;type:boolean"` Ts time.Time `greptime:"timestamp;column:ts;type:timestamp;precision:millisecond"` } func (monitor) TableName() string { return monitorTableName } monitors := []monitor{ { ID: randomId(), Host: "127.0.0.1", Memory: 1, Cpu: 1.0, Temperature: -1, Ts: time1, Running: true, }, { ID: randomId(), Host: "127.0.0.2", Memory: 2, Cpu: 2.0, Temperature: -2, Ts: time2, Running: true, }, } resp, err := client.StreamWriteObject(context.Background(), monitors)
func (*Client) Write ¶ added in v0.2.0
Write is to write the data into GreptimeDB via explicit schema.
tbl, err := table.New(<tableName>) // add column at first. This is to define the schema of the table. tbl.AddTagColumn("tag1", types.INT64) tbl.AddFieldColumn("field1", types.STRING) tbl.AddFieldColumn("field2", types.FLOAT64) tbl.AddTimestampColumn("timestamp", types.TIMESTAMP_MILLISECOND) timestamp := time.Now() // you can add multiple row(s). This is the real data. tbl.AddRow(1, "hello", 1.1, timestamp) // write data into GreptimeDB resp, err := client.Write(context.Background(), tbl)
func (*Client) WriteObject ¶ added in v0.3.0
WriteObject is like [Write] to write the data into GreptimeDB, but schema is defined in the struct tag.
type Monitor struct { ID int64 `greptime:"tag;column:id;type:int64"` Host string `greptime:"tag;column:host;type:string"` Memory uint64 `greptime:"field;column:memory;type:uint64"` Cpu float64 `greptime:"field;column:cpu;type:float64"` Temperature int64 `greptime:"field;column:temperature;type:int64"` Running bool `greptime:"field;column:running;type:boolean"` Ts time.Time `greptime:"timestamp;column:ts;type:timestamp;precision:millisecond"` } func (Monitor) TableName() string { return monitorTableName } monitors := []Monitor{ { ID: randomId(), Host: "127.0.0.1", Memory: 1, Cpu: 1.0, Temperature: -1, Ts: time1, Running: true, }, { ID: randomId(), Host: "127.0.0.2", Memory: 2, Cpu: 2.0, Temperature: -2, Ts: time2, Running: true, }, } resp, err := client.WriteObject(context.Background(), monitors)
type Config ¶ added in v0.2.0
type Config struct { Host string // no scheme or port included. example: 127.0.0.1 Port int // default: 4001 Username string Password string Database string // the default database // contains filtered or unexported fields }
Config is to define how the Client behaves.
- Host is 127.0.0.1 in local environment.
- Port default value is 4001.
- Username and Password can be left to empty in local environment. you can find them in GreptimeCloud service detail page.
- Database is the default database the client will operate on. But you can change the database in InsertRequest or QueryRequest.
func (*Config) WithAuth ¶ added in v0.2.0
WithAuth helps to specify the Basic Auth username and password. Leave them empty if you are in local environment.
func (*Config) WithDatabase ¶ added in v0.2.0
WithDatabase helps to specify the default database the client operates on.
func (*Config) WithDialOption ¶ added in v0.4.0
func (c *Config) WithDialOption(opt grpc.DialOption) *Config
WithDialOption helps to specify the dial option which has not been supported by ingester sdk yet.
func (*Config) WithInsecure ¶ added in v0.4.0
TODO(yuanbohan): support more tls options
func (*Config) WithKeepalive ¶ added in v0.2.0
WithKeepalive helps to set the keepalive option.
- time. After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive. If set below 10s, a minimum value of 10s will be used instead.
- timeout. After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed.
func (*Config) WithMeterProvider ¶ added in v0.5.3
func (c *Config) WithMeterProvider(p metric.MeterProvider) *Config
WithMeterProvider provides a MeterProvider for SDK. If metrics colleciton is not enabled, then this option has no effect. If metrics colleciton is enabled and this option is not provide. the global MeterProvider will be used.
func (*Config) WithMetricsEnabled ¶ added in v0.5.3
WithMetricsEnabled enables/disables collection of SDK's metrics. Disabled by default.
func (*Config) WithPort ¶ added in v0.2.0
WithPort set the Port field. Do not change it if you have no idea what it is.
func (*Config) WithTraceProvider ¶ added in v0.5.3
func (c *Config) WithTraceProvider(p trace.TracerProvider) *Config
WithTraceProvider provides a TracerProvider for SDK. If traces colleciton is not enabled, then this option has no effect. If traces colleciton is enabled and this option is not provide. the global MeterProvider will be used.
func (*Config) WithTracesEnabled ¶ added in v0.5.3
WithTracesEnabled enables/disables collection of SDK's traces. Disabled by default.