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

Added option to add a rentention policy with infinite duration #87

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ It currently supports
10. Chunking Support in queries
11. Drop databases, measurements or points
12. Get series count or points count for a measurement</PackageReleaseNotes>
<AssemblyVersion>0.9.0.0</AssemblyVersion>
<FileVersion>0.9.0.0</FileVersion>
<AssemblyVersion>0.10.0.0</AssemblyVersion>
<FileVersion>0.10.0.0</FileVersion>
<PackageTags>InfluxDB Influx TSDB TimeSeries InfluxData Chunking retention RetentionPolicy</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/AdysTech.InfluxDB.Client.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0.0")]
[assembly: AssemblyFileVersion("0.9.0.0")]
[assembly: AssemblyVersion("0.10.0.0")]
[assembly: AssemblyFileVersion("0.10.0.0")]
22 changes: 11 additions & 11 deletions src/DataStructures/InfluxRetentionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InfluxRetentionPolicy : IInfluxRetentionPolicy
public string Name { get; set; }

/// <summary>
/// Duration of the retention period that the policy is defining
/// Duration of the retention period that the policy is defining. If Duration is lower or equal TimeSpan.Zero retention policy will be Infinite
/// </summary>
public TimeSpan Duration { get; set; }

Expand All @@ -43,21 +43,21 @@ public class InfluxRetentionPolicy : IInfluxRetentionPolicy
/// </summary>
public bool Saved { get; internal set; }

public InfluxRetentionPolicy ()
public InfluxRetentionPolicy()
{
ReplicaN = 1;
}

internal string GetCreateSyntax ()
internal string GetCreateSyntax()
{
if (!String.IsNullOrWhiteSpace (DBName) && !String.IsNullOrWhiteSpace (Name) && Duration >= TimeSpan.FromMinutes (60))
return $"CREATE RETENTION POLICY \"{Name}\" ON \"{DBName}\" DURATION {Duration.TotalMinutes}m REPLICATION {ReplicaN} {(IsDefault ? " DEFAULT" : "")}";
else if (Duration < TimeSpan.FromMinutes (60))
throw new ArgumentException ("Minimum retention duration is 1 hour");
else if (String.IsNullOrWhiteSpace (Name))
throw new ArgumentException ("Name not set");
else if (String.IsNullOrWhiteSpace (DBName))
throw new ArgumentException ("DBName is not set");
if (!String.IsNullOrWhiteSpace(DBName) && !String.IsNullOrWhiteSpace(Name) && Duration >= TimeSpan.FromMinutes(60) || Duration <= TimeSpan.Zero)
return $"CREATE RETENTION POLICY \"{Name}\" ON \"{DBName}\" DURATION {(Duration <= TimeSpan.Zero ? "INF" : Duration.TotalMinutes + "m")} REPLICATION {ReplicaN} {(IsDefault ? " DEFAULT" : "")}";
else if (Duration < TimeSpan.FromMinutes(60))
throw new ArgumentException("Minimum retention duration is 1 hour");
else if (String.IsNullOrWhiteSpace(Name))
throw new ArgumentException("Name not set");
else if (String.IsNullOrWhiteSpace(DBName))
throw new ArgumentException("DBName is not set");
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/IInfluxRetentionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public interface IInfluxRetentionPolicy
string Name { get; set; }

/// <summary>
/// Duration of the retention period that the policy is defining
/// Duration of the retention period that the policy is defining. If Duration is lower or equal TimeSpan.Zero retention policy will be Infinite
/// </summary>
TimeSpan Duration { get; set; }
TimeSpan Duration { get; set; }

/// <summary>
/// If this policy instance is the default policy for the DB
Expand Down
10 changes: 10 additions & 0 deletions tests/InfluxDBClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ public async Task TestCreateRetentionPolicy()
Assert.IsTrue(p.Saved, "CreateRetentionPolicyAsync failed");
}

[TestMethod, TestCategory("Create")]
public async Task TestCreateRetentionPolicyInfinite()
{
var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
var p = new InfluxRetentionPolicy() { Name = "Test3", DBName = dbName, Duration = TimeSpan.Zero, IsDefault = false };

var r = await client.CreateRetentionPolicyAsync(p);
Assert.IsTrue(p.Saved, "CreateRetentionPolicyAsync failed");
}

[TestMethod, TestCategory("Get")]
public async Task TestGetContinuousQueriesAsync()
{
Expand Down