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

docs: client libraries outline #741

Merged
merged 13 commits into from
Jan 12, 2024
13 changes: 7 additions & 6 deletions docs/.vitepress/theme/template.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,22 @@ const getAbsolutePath = (relativePath, currentPath) => {
}

const getReplacementsMap = content => {
const regex = /{template ([\s\S]*?)}/g
const matches = content.match(regex).map(match => match.replace(/{template ([\s\S]*)}/, ($1, $2) => $2))
const regex = /\{template ([\s\S]*?)%\}/g
const matches = content.match(regex).map(match => match.replace(/\{template ([\s\S]*)%\}/, ($1, $2) => $2))
const map = {}
matches.forEach(match => {
const target = match.split('%')
const key = target[0]
const value = target[1].slice(target[1].indexOf('\n') + 1)
const targetKey = match.slice(0, match.indexOf('%'))
const targetValue = match.slice(match.indexOf('%') + 1)
const key = targetKey
const value = targetValue.slice(targetValue[1].indexOf('\n') + 1)
map[key] = value
})
return map
}

const getFileContent = (template, file) => {
const replacementsMap = getReplacementsMap(file)
return template.replace(/{template ([\s\S]*?)%}/g, (match, key) => replacementsMap[key] || match)
return template.replace(/\{template ([\s\S]*?)%%\}/g, (match, key) => replacementsMap[key] || match)
}

function slash(p) {
Expand Down
2 changes: 1 addition & 1 deletion docs/v0.4/en/getting-started/quick-start/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
go run github.com/GreptimeCloudStarters/quick-start-go@latest -endpoint=http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/en/getting-started/quick-start/influxdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
curl -L https://raw.githubusercontent.com/GreptimeCloudStarters/quick-start-influxdb-line-protocol/main/quick-start.sh | bash -s -- -e http://localhost:4000/v1/influxdb/write
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/en/getting-started/quick-start/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ curl -L https://github.com/GreptimeCloudStarters/quick-start-java/releases/lates
--output quick-start.jar && java -jar quick-start.jar -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/en/getting-started/quick-start/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ template: quick-start-template.md
```shell
npx greptime-cloud-quick-start@latest --endpoint=http://localhost:4000/v1/otlp/v1/metrics
```
}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/en/getting-started/quick-start/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
pipx run --no-cache greptime-cloud-quick-start -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Write Data

{template write-data%}
{template write-data%%}

## Visualize Data with Grafana
<!--@include: ./visualize-data-by-grafana.md-->
Expand Down
2 changes: 1 addition & 1 deletion docs/v0.4/zh/getting-started/quick-start/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template: quick-start-template.md
go run github.com/GreptimeCloudStarters/quick-start-go@latest -endpoint=http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>

2 changes: 1 addition & 1 deletion docs/v0.4/zh/getting-started/quick-start/influxdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
curl -L https://raw.githubusercontent.com/GreptimeCloudStarters/quick-start-influxdb-line-protocol/main/quick-start.sh | bash -s -- -e http://localhost:4000/v1/influxdb/write
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/zh/getting-started/quick-start/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ curl -L https://github.com/GreptimeCloudStarters/quick-start-java/releases/lates
--output quick-start.jar && java -jar quick-start.jar -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/zh/getting-started/quick-start/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ template: quick-start-template.md
```shell
npx greptime-cloud-quick-start@latest --endpoint=http://localhost:4000/v1/otlp/v1/metrics
```
}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.4/zh/getting-started/quick-start/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
pipx run --no-cache greptime-cloud-quick-start -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## 写入数据

{template write-data%}
{template write-data%%}

## 使用 Grafana 可视化数据
<!--@include: ./visualize-data-by-grafana.md-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ of [Apache Arrow Flight](https://arrow.apache.org/docs/format/Flight.html). If y
GreptimeDB in a programming language you are familiar with, please read on!

> Currently, the gRPC SDK is written in Java and Go, and you can find more details about
> [Java](/reference/sdk/java.md) and [Go](/reference/sdk/go.md).
> [Java](/user-guide/client-libraries/java.md) and [Go](/user-guide/client-libraries/go.md).

## `GreptimeDatabase` Service

Expand Down
2 changes: 1 addition & 1 deletion docs/v0.5/en/getting-started/quick-start/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
go run github.com/GreptimeCloudStarters/quick-start-go@latest -endpoint=http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.5/en/getting-started/quick-start/influxdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
curl -L https://raw.githubusercontent.com/GreptimeCloudStarters/quick-start-influxdb-line-protocol/main/quick-start.sh | bash -s -- -e http://localhost:4000/v1/influxdb/write
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.5/en/getting-started/quick-start/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ curl -L https://github.com/GreptimeCloudStarters/quick-start-java/releases/lates
--output quick-start.jar && java -jar quick-start.jar -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.5/en/getting-started/quick-start/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ template: quick-start-template.md
```shell
npx greptime-cloud-quick-start@latest --endpoint=http://localhost:4000/v1/otlp/v1/metrics
```
}
%}

</docs-template>
2 changes: 1 addition & 1 deletion docs/v0.5/en/getting-started/quick-start/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ template: quick-start-template.md
pipx run --no-cache greptime-cloud-quick-start -e http://localhost:4000/v1/otlp/v1/metrics
```

}
%}

</docs-template>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Write Data

{template write-data%}
{template write-data%%}

## Visualize Data with Grafana
<!--@include: ./visualize-data-by-grafana.md-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Go SDK

The GreptimeDB Go SDK uses gRPC to communicate with the database. For more information on how to use the SDK, please refer to the [Go SDK documentation](https://docs.greptime.com/user-guide/clients/sdk-libraries/go).
The GreptimeDB Go ingester library utilizes gRPC for writing data to the database. For how to use the library, please refer to the [Go library documentation](https://docs.greptime.com/user-guide/client-libraries/go).

To connect to GreptimeCloud, using information below:

Expand Down
30 changes: 6 additions & 24 deletions docs/v0.5/en/greptimecloud/integrations/sdk-libraries/java.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Java SDK

The GreptimeDB Java SDK uses gRPC to communicate with the database. For more information on how to use the SDK, please refer to the [Java SDK documentation](https://docs.greptime.com/user-guide/clients/sdk-libraries/java).
The GreptimeDB Java ingester library utilizes gRPC for writing data to the database. For how to use the library, please refer to the [Java library documentation](https://docs.greptime.com/user-guide/client-libraries/java).

To connect to GreptimeCloud, using information below:

Expand All @@ -10,32 +10,14 @@ To connect to GreptimeCloud, using information below:
- Username: `<username>`
- Password: `<password>`

The following code snippet shows how to create a client.
The following code snippet shows how to connect to database:

```java
String endpoint = "<host>:4001";
String database = "<dbname>";
String[] endpoints = {"<host>:4001"};
AuthInfo authInfo = new AuthInfo("<username>", "<password>");

GreptimeOptions opts = GreptimeOptions.newBuilder(endpoint)
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database)
.authInfo(authInfo)
.writeMaxRetries(1)
.readMaxRetries(2)
.routeTableRefreshPeriodSeconds(-1)
.build();

GreptimeDB greptimeDB = new GreptimeDB();

if (!greptimeDB.init(opts)) {
throw new RuntimeException("Fail to start GreptimeDB client");
}
```

After creating a GreptimeDB client, you can set database while writing data or querying data. For example query data:

```java
QueryRequest request = QueryRequest.newBuilder()
.exprType(SelectExprType.Sql)
.ql("SELECT * FROM monitor;")
.databaseName("<dbname>")
.build();
GreptimeDB client = GreptimeDB.create(opts);
```
38 changes: 2 additions & 36 deletions docs/v0.5/en/reference/sdk/go.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
# Go SDK
# THIS PAGE HAS BEEN DEPRECATED

A Go Client for GreptimeDB, which is compatible with GreptimeDB protocol and lightweight.

## Features

- Concurrent safe
- Non-blocking
- Easy to use with Metric and Series struct
- Support Sql and PromQL in querying

## How to use

Please refer to User Guide chapter to learn [how to install SDK](../../user-guide/clients/sdk-libraries/go.md),
[write data](../../user-guide/write-data/sdk-libraries/go.md) and [query data](../../user-guide/query-data/sdk-libraries/go.md).

## Configuration

| Name | Description |
| :------- | :-------------------------------------------------------------------- |
| Host | GreptimeDB server host |
| Port | Default is 4001 |
| Username | Leave the field empty if connecting a database without authentication |
| Password | Leave the field empty if connecting a database without authentication |
| Database | Default database to operate on |

## Usage Examples

For fully runnable code snippets and explanations for common methods, see the [Examples][example].

<!-- link -->

[example]: https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-client-go#example-package

## API

Please refer to [API Document](https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-client-go).
Please refer to the [Client Libraries](/user-guide/client-libraries/overview.md) for up-to-date information.
109 changes: 2 additions & 107 deletions docs/v0.5/en/reference/sdk/java.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,3 @@
# Java SDK
# THIS PAGE HAS BEEN DEPRECATED

A Java Client for GreptimeDB, which is compatible with GreptimeDB protocol and lightweight.

## Features

- SPI-based extensible network transport layer; provides the default implementation by using the
gRPC framework
- Non-blocking, purely asynchronous API, easy to use
- Automatically collects various performance metrics by default. Users can then configure them and
write to local files
- Users can take in-memory snapshots of critical objects, configure them, and write to local files.
This is helpful when troubleshooting complex issues

## How to use

Please refer to User Guide chapter to learn [how to install SDK](../../user-guide/clients/sdk-libraries/java.md), [write data](../../user-guide/write-data/sdk-libraries/java.md) and [query data](../../user-guide/query-data/sdk-libraries/java.md).

## Global Options (System properties / Java -Dxxx)

| Name | Description |
| :--------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| greptimedb.use_os_signal | Whether or not to use OS Signal, SDK listens for SIGUSR2 signals by default and can outputs some information. This is helpful when troubleshooting complex issues. |
| greptimedb.signal.out_dir | Signal handler can output to the specified directory, default is the process start directory. |
| greptimedb.available_cpus | Specify the number of available cpus, the default is to use the full number of cpus of the current environment. |
| greptimedb.reporter.period_minutes | Metrics reporter timed output period, default 30 minutes. |
| greptimedb.read.write.rw_logging | Whether to print logs for each read/write operation, default off. |

## Metrics&Display

At runtime, users can use the SIGUSR2 signal of the Linux platform to output
the status information (display) of the node and the metrics.

### How

```shell
kill -s SIGUSR2 pid
```

The relevant information is output to the specified directory.

By default, 2 files are generated in the program's working directory
(cwd: `lsof -p $pid | grep cwd`)

- greptimedb_client_metrics.log.xxx: It records all metrics information for the current
client node
- greptimedb_client_display.log.xxx: It records important memory state information about the
current client

### List of Metrics (constantly updated)

| Name | Description |
| :--------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------- |
| thread_pool.${thread_pool_name} [timer] | Thread pool execution task time statistics. |
| scheduled_thread_pool.${schedule_thread_pool_name} [timer] | Schedule thread pool execution task time statistics. |
| async_write_pool.time [timer] | Asynchronous pool time statistics for asynchronous write tasks in SDK, this is important and it is recommended to focus on it. |
| async_read_pool.time [timer] | Asynchronous pool time statistics for asynchronous read tasks in SDK, this is important and it is recommended to focus on it. |
| write_rows_success_num [histogram] | Statistics on the number of successful writes. |
| write_rows_failure_num [histogram] | Statistics on the number of data entries that failed to write. |
| write_failure_num [meter] | Statistics on the number of failed writes. |
| write_qps [meter] | Write Request QPS |
| write_by_retries\_${n} [meter] | QPS for the nth retry write, n == 0 for the first write (non-retry), n > 3 will be counted as n == 3 |
| read_rows_num [histogram] | Statistics of the number of data items per query. |
| read_failure_num [meter] | Statistics of the number of failed queries. |
| serializing_executor_single_task_timer\_${name} [timer] | Serializing executor. Single task execution time consumption statistics |
| serializing_executor_drain_timer\_${name} [timer] | Serializing executor. Drains all tasks for time consumption statistics |
| serializing_executor_drain_num\_${name} [histogram] | Serializing executor. Statistics on the number of draining tasks |

## Magic Tools

### How to use `kill -s SIGUSR2 $pid`

The first time you execute `kill -s SIGUSR2 $pid` you will see the following help messages on
the log output, including:

- Turn on/off the output of the condensed version of the read/write log.
- Turn on/off limter
- Export in-memory metrics and memory state information of important objects to a local file

### Just follow the help information

```text
- -- GreptimeDBClient Signal Help --
- Signal output dir: /Users/xxx/xxx
-
- How to open or close read/write log(The second execution means close):
- [1] `cd /Users/xxx/xxx`
- [2] `touch rw_logging.sig`
- [3] `kill -s SIGUSR2 $pid`
- [4] `rm rw_logging.sig`
-
- How to get metrics and display info:
- [1] `cd /Users/xxx/xxx`
- [2] `rm *.sig`
- [3] `kill -s SIGUSR2 $pid`
-
- The file signals that is currently open:
- rw_logging.sig
-
```

## Usage Examples

For fully runnable code snippets and explanations for common methods, see the [Usage Examples](https://github.com/GreptimeTeam/greptimedb-client-java/tree/main/greptimedb-example/src/main/java/io/greptime/example).

## API

Please refer to [API Document](https://javadoc.io/doc/io.greptime/greptimedb-protocol/latest/index.html).
Please refer to the [Client Libraries](/user-guide/client-libraries/overview.md) for up-to-date information.
Loading
Loading