Skip to content

Commit 0beb204

Browse files
authored
docs: Clarify how to use a client with InfluxDB 1.8 (#77)
1 parent c5f00c1 commit 0beb204

File tree

5 files changed

+120
-10
lines changed

5 files changed

+120
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
### Features
44
1. [#70](https://github.com/influxdata/influxdb-client-csharp/pull/70): Optimized mapping of measurements into `PointData`
55

6-
### Bugs
6+
### Bug Fixes
77
1. [#69](https://github.com/influxdata/influxdb-client-csharp/pull/69): Write buffer uses correct flush interval and batch size under heavy load
88

9+
### Documentation
10+
1. [#77](https://github.com/influxdata/influxdb-client-csharp/pull/77): Clarify how to use a client with InfluxDB 1.8
11+
912
### Dependencies
1013
1. [#74](https://github.com/influxdata/influxdb-client-csharp/pull/74): update CsvHelper to [15.0.4,16.0)
1114

@@ -15,7 +18,7 @@
1518
1. [#61](https://github.com/influxdata/influxdb-client-csharp/issues/61): Set User-Agent to influxdb-client-csharp/VERSION for all requests
1619
1. [#64](https://github.com/influxdata/influxdb-client-csharp/issues/64): Add authentication with Username and Password for Client.Legacy
1720

18-
### Bugs
21+
### Bug Fixes
1922
1. [#63](https://github.com/influxdata/influxdb-client-csharp/pull/63): Correctly parse CSV where multiple results include multiple tables
2023

2124
## 1.5.0 [2020-02-14]
@@ -35,7 +38,7 @@
3538
### CI
3639
1. [#54](https://github.com/influxdata/influxdb-client-csharp/pull/54): Added beta release to continuous integration
3740

38-
### Bugs
41+
### Bug Fixes
3942
1. [#56](https://github.com/influxdata/influxdb-client-csharp/issues/56): WriteApi is disposed after a buffer is fully processed
4043

4144
## 1.3.0 [2019-12-06]
@@ -47,7 +50,7 @@
4750
### API
4851
1. [#46](https://github.com/influxdata/influxdb-client-csharp/pull/46): Updated swagger to latest version
4952

50-
### Bugs
53+
### Bug Fixes
5154
1. [#45](https://github.com/influxdata/influxdb-client-csharp/issues/45): Assemblies are strong-named
5255
2. [#48](https://github.com/influxdata/influxdb-client-csharp/pull/48): Packing library icon into a package
5356

@@ -71,7 +74,7 @@
7174
### API
7275
1. [#36](https://github.com/influxdata/influxdb-client-csharp/issues/36): Updated swagger to latest version
7376

74-
### Bugs
77+
### Bug Fixes
7578
1. [#31](https://github.com/influxdata/influxdb-client-csharp/issues/31): Drop NaN and infinity values from fields when writing to InfluxDB
7679
1. [#39](https://github.com/influxdata/influxdb-client-csharp/pull/39): FluxCSVParser uses a CultureInfo for parsing string to double
7780

@@ -80,7 +83,7 @@
8083
### Features
8184
1. [#29](https://github.com/influxdata/influxdb-client-csharp/issues/29): Added support for gzip compression of query response and write body
8285

83-
### Bugs
86+
### Bug Fixes
8487
1. [#27](https://github.com/influxdata/influxdb-client-csharp/issues/27): The org parameter takes either the ID or Name interchangeably
8588

8689
### API
@@ -92,7 +95,7 @@
9295
1. [#18](https://github.com/influxdata/influxdb-client-csharp/issues/18): Auto-configure client from configuration file
9396
1. [#20](https://github.com/influxdata/influxdb-client-csharp/issues/19): Possibility to specify default tags
9497

95-
### Bugs
98+
### Bug Fixes
9699
1. [#24](https://github.com/influxdata/influxdb-client-csharp/issues/24): The data point without field should be ignored
97100

98101
## 1.0.0.M1

Client.Test/InfluxDbClientFactoryTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ public void LoadFromConfiguration()
144144
Assert.AreEqual("California Miner", defaultTags["customer"]);
145145
Assert.AreEqual("${SensorVersion}", defaultTags["version"]);
146146
}
147+
148+
[Test]
149+
public void V1Configuration()
150+
{
151+
var client = InfluxDBClientFactory.CreateV1("http://localhost:8086", "my-username", "my-password".ToCharArray(), "database", "week");
152+
153+
var options = GetDeclaredField<InfluxDBClientOptions>(client.GetType(), client, "_options");
154+
Assert.AreEqual("http://localhost:8086", options.Url);
155+
Assert.AreEqual("-", options.Org);
156+
Assert.AreEqual("database/week", options.Bucket);
157+
Assert.AreEqual("my-username:my-password".ToCharArray(), options.Token);
158+
159+
client = InfluxDBClientFactory.CreateV1("http://localhost:8086", null, null, "database", null);
160+
161+
options = GetDeclaredField<InfluxDBClientOptions>(client.GetType(), client, "_options");
162+
Assert.AreEqual("http://localhost:8086", options.Url);
163+
Assert.AreEqual("-", options.Org);
164+
Assert.AreEqual("database/", options.Bucket);
165+
Assert.AreEqual(":".ToCharArray(), options.Token);
166+
}
147167

148168
private static T GetDeclaredField<T>(IReflect type, object instance, string fieldName)
149169
{

Client/InfluxDBClientFactory.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static InfluxDBClient Create()
1919

2020
return Create(options);
2121
}
22-
22+
2323
/// <summary>
2424
/// Create a instance of the InfluxDB 2.0 client. The url could be a connection string with various configurations.
2525
/// <para>
@@ -73,6 +73,31 @@ public static InfluxDBClient Create(string url, char[] token)
7373
return Create(options);
7474
}
7575

76+
/// <summary>
77+
/// Create a instance of the InfluxDB 2.0 client to connect into InfluxDB 1.8.
78+
/// </summary>
79+
/// <param name="url">the url to connect to the InfluxDB 1.8</param>
80+
/// <param name="username">authorization username</param>
81+
/// <param name="password">authorization password</param>
82+
/// <param name="database">database name</param>
83+
/// <param name="retentionPolicy">retention policy</param>
84+
/// <returns>client</returns>
85+
public static InfluxDBClient CreateV1(string url, string username, char[] password, string database,
86+
string retentionPolicy)
87+
{
88+
Arguments.CheckNonEmptyString(database, nameof(database));
89+
90+
var options = InfluxDBClientOptions.Builder
91+
.CreateNew()
92+
.Url(url)
93+
.Org("-")
94+
.AuthenticateToken($"{username}:{new string(password)}".ToCharArray())
95+
.Bucket($"{database}/{retentionPolicy}")
96+
.Build();
97+
98+
return Create(options);
99+
}
100+
76101
/// <summary>
77102
/// Create a instance of the InfluxDB 2.0 client.
78103
/// </summary>
@@ -94,7 +119,8 @@ public static InfluxDBClient Create(InfluxDBClientOptions options)
94119
/// <param name="org">the name of an organization</param>
95120
/// <param name="bucket">the name of a bucket</param>
96121
/// <returns>Created default user, bucket, org.</returns>
97-
public static async Task<OnboardingResponse> Onboarding(string url, string username, string password, string org,
122+
public static async Task<OnboardingResponse> Onboarding(string url, string username, string password,
123+
string org,
98124
string bucket)
99125
{
100126
Arguments.CheckNonEmptyString(url, nameof(url));

Examples/InfluxDB18Example.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using InfluxDB.Client;
4+
using InfluxDB.Client.Writes;
5+
6+
namespace Examples
7+
{
8+
public class InfluxDB18Example
9+
{
10+
// change name of method to Main
11+
public static async Task MainDisabled(string[] args)
12+
{
13+
const string database = "telegraf";
14+
const string retentionPolicy = "autogen";
15+
16+
var client = InfluxDBClientFactory.CreateV1("http://localhost:8086",
17+
"username",
18+
"password".ToCharArray(),
19+
database,
20+
retentionPolicy);
21+
22+
Console.WriteLine("*** Write Points ***");
23+
24+
using (var writeApi = client.GetWriteApi())
25+
{
26+
var point = PointData.Measurement("mem")
27+
.Tag("host", "host1")
28+
.Field("used_percent", 28.43234543);
29+
30+
writeApi.WritePoint(point);
31+
}
32+
33+
Console.WriteLine("*** Query Points ***");
34+
35+
var query = $"from(bucket: \"{database}/{retentionPolicy}\") |> range(start: -1h)";
36+
var fluxTables = await client.GetQueryApi().QueryAsync(query);
37+
var fluxRecords = fluxTables[0].Records;
38+
fluxRecords.ForEach(record =>
39+
{
40+
Console.WriteLine($"{record.GetTime()} {record.GetMeasurement()}: {record.GetField()} {record.GetValue()}");
41+
});
42+
43+
client.Dispose();
44+
}
45+
}
46+
}

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
This repository contains the reference C# client for the InfluxDB 2.0.
1212

13-
#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+. For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-csharp](https://github.com/influxdata/influxdb-csharp) client library.
13+
#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+ ([see details](#influxdb-18-api-compatibility)). For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-csharp](https://github.com/influxdata/influxdb-csharp) client library.
1414

1515
- [Features](#features)
1616
- [Documentation](#documentation)
@@ -213,6 +213,21 @@ namespace Examples
213213
}
214214
```
215215

216+
### InfluxDB 1.8 API compatibility
217+
218+
[InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/latest/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.0. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.0 Cloud or open source.
219+
220+
The following forward compatible APIs are available:
221+
222+
| API | Endpoint | Description |
223+
|:----------|:----------|:----------|
224+
| [QueryApi.cs](Client/QueryApi.cs) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.0 API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |
225+
| [WriteApi.cs](Client/WriteApi.cs) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.0 API |
226+
| [HealthAsync](Client/InfluxDBClient.cs#L362) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance |
227+
228+
For detail info see [InfluxDB 1.8 example](Examples/InfluxDB18Example.cs).
229+
230+
216231
### Flux queries in InfluxDB 1.7+
217232

218233
The following example demonstrates querying using the Flux language.

0 commit comments

Comments
 (0)