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

InfluxDB Health Check #704

Merged
merged 96 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
7c8eef0
InfluxDB Health Check
maikebing Dec 29, 2020
894a2a7
Suggested change
maikebing Dec 30, 2020
262bff3
Suggested change
maikebing Dec 30, 2020
25267bf
Merge remote-tracking branch 'remotes/Xabaril/master' into HealthChec…
maikebing Dec 30, 2020
d6f4c0e
Merge branch 'master' into HealthChecks_InfluxDB
maikebing Jan 6, 2021
32674e3
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
maikebing Jan 8, 2021
935c8a9
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
9d5c706
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
2ae2039
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
aaec646
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
13105dd
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
d460541
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
ea27de1
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
d5ac3f9
Update src/HealthChecks.InfluxDB/README.md
maikebing Jan 8, 2021
87862a1
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
587aa4d
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
0acbe8b
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
643e3d6
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
d81bd2e
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
8c05252
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
b3c8883
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
fbe5fc8
Update InfluxDBHealthCheckBuilderExtensions.cs
maikebing Jan 8, 2021
8e63b13
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
cea0cac
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
48e5e0a
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Jan 8, 2021
0c1ca77
Merge branch 'master' into HealthChecks_InfluxDB
maikebing May 7, 2021
1955469
Merge remote-tracking branch 'remotes/Xabaril/master' into HealthChec…
maikebing Mar 10, 2022
4f1a040
Use PingAsync and ReadyAsync to health check
maikebing Mar 10, 2022
0852871
fix props
maikebing Mar 10, 2022
5f69d6b
fix sln
maikebing Mar 10, 2022
8ed7e82
modify version
maikebing Mar 10, 2022
9cdfc4e
Update src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
maikebing Mar 10, 2022
0643040
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
maikebing Mar 10, 2022
f5b46cb
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Mar 10, 2022
588aa22
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Mar 10, 2022
378d986
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
maikebing Mar 10, 2022
0d4ba25
fix some code
maikebing Mar 10, 2022
1bf1cf1
Merge branch 'HealthChecks_InfluxDB' of https://github.com/maikebing/…
maikebing Mar 10, 2022
8023fb9
fix some code
maikebing Mar 10, 2022
07155fc
add ci cd and test
maikebing Mar 10, 2022
406f656
Merge remote-tracking branch 'remotes/Xabaril/master' into HealthChec…
maikebing Dec 23, 2022
9b26464
upgrade to new indexdb client
maikebing Dec 23, 2022
c25316c
Update .github/workflows/healthchecks_influxdb_cd.yml
sungam3r Dec 23, 2022
d042df5
Update .github/workflows/healthchecks_influxdb_cd.yml
sungam3r Dec 23, 2022
3eea322
Update .github/workflows/healthchecks_influxdb_cd.yml
sungam3r Dec 23, 2022
8e06188
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
4ca8000
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
f957c80
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
1269197
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
45c7c64
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
08f7456
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
9e7cedc
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
6353773
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
8ee37d3
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
7a063f9
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
85b5f5c
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
a3a50ae
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
250cf3d
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
faa3295
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 23, 2022
ca151ec
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
f3fd97d
Update .github/workflows/healthchecks_influxdb_cd_preview.yml
sungam3r Dec 23, 2022
5730e42
Update README.md
sungam3r Dec 23, 2022
118a97b
Update README.md
sungam3r Dec 23, 2022
c4e18ef
Update src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
sungam3r Dec 23, 2022
9fac1fe
Update src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
sungam3r Dec 23, 2022
1c0ec48
Update src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
sungam3r Dec 23, 2022
bef17ad
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
sungam3r Dec 23, 2022
d49de6a
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
sungam3r Dec 23, 2022
0a28f17
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
sungam3r Dec 23, 2022
dd00cdd
Update test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthChec…
sungam3r Dec 23, 2022
6467528
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
sungam3r Dec 23, 2022
95f0d57
Update test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthChec…
sungam3r Dec 23, 2022
595d4d9
fix some things .
maikebing Dec 23, 2022
c07d6f9
use InfluxDBHealthCheckOptions with single ctor in InfluxDBHealthCheck.
maikebing Dec 23, 2022
ab7575c
Update test/HealthChecks.InfluxDB.Tests/DependencyInjection/Registrat…
sungam3r Dec 23, 2022
178b18c
Update src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
sungam3r Dec 23, 2022
d1e9a80
Update test/HealthChecks.InfluxDB.Tests/DependencyInjection/Registrat…
sungam3r Dec 23, 2022
8cc6bc7
Update test/HealthChecks.InfluxDB.Tests/DependencyInjection/Registrat…
sungam3r Dec 23, 2022
97d7d51
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
849422f
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
c5e9671
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
9723e51
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
be1bb2c
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
28e6dc8
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
274f163
file-scoped
maikebing Dec 23, 2022
85d9bea
Merge branch 'HealthChecks_InfluxDB' of https://github.com/maikebing/…
maikebing Dec 23, 2022
5382a7b
Update test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthChec…
sungam3r Dec 23, 2022
fd0aea9
influxdb
maikebing Dec 23, 2022
b73ae6f
Merge branch 'HealthChecks_InfluxDB' of https://github.com/maikebing/…
maikebing Dec 23, 2022
266400f
Apply suggestions from code review
sungam3r Dec 23, 2022
a47c2bb
Update src/HealthChecks.InfluxDB/DependencyInjection/InfluxDBHealthCh…
sungam3r Dec 23, 2022
6f2a28e
<see cref="TimeSpan"/>
maikebing Dec 23, 2022
f26cc36
Merge branch 'HealthChecks_InfluxDB' of https://github.com/maikebing/…
maikebing Dec 23, 2022
ba0cf2b
fix for test
maikebing Dec 24, 2022
48167ba
Merge remote-tracking branch 'remotes/Xabaril/master' into HealthChec…
maikebing Dec 24, 2022
d1dd3b1
Update .github/workflows/healthchecks_influxdb_ci.yml
sungam3r Dec 24, 2022
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
30 changes: 30 additions & 0 deletions .github/workflows/healthchecks_influxdb_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: HealthChecks InfluxDB CD

on:
push:
tags:
- release-influxdb-*
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
- release-all-*

jobs:
build:
env:
BUILD_CONFIG: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Restore
run: dotnet restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj -c $BUILD_CONFIG
- name: Pack
run: dotnet pack --no-build ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj -c $BUILD_CONFIG -o ./artifacts
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.InfluxDB.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate

31 changes: 31 additions & 0 deletions .github/workflows/healthchecks_influxdb_cd_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: HealthChecks InfluxDB Preview CD

on:
push:
tags:
- preview-influxdb-*
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
- preview-all-*

jobs:
build:
env:
BUILD_CONFIG: Release
VERSION_SUFFIX: -rc2.${{ github.run_number }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Restore
run: dotnet restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj -c $BUILD_CONFIG
- name: dotnet pack
run: dotnet pack --no-build ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.InfluxDB.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate

57 changes: 57 additions & 0 deletions .github/workflows/healthchecks_influxdb_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: HealthChecks InfluxDB CI

on:
workflow_dispatch:
push:
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
branches: [ master ]
paths:
- src/HealthChecks.InfluxDB/**
- test/HealthChecks.InfluxDB.Tests/**
- .github/workflows/healthchecks_influxdb_ci.yml
- Directory.Build.props
- Directory.Build.targets
tags-ignore:
- release-*
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
- preview-*

pull_request:
branches: [ master ]
paths:
- src/HealthChecks.InfluxDB/**
- test/HealthChecks.InfluxDB.Tests/**
- .github/workflows/healthchecks_influxdb_ci.yml
- Directory.Build.props
- Directory.Build.targets

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Restore
run: dotnet restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj &&
dotnet restore ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj || (echo "Run 'dotnet format' to fix whitespace issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj || (echo "Run 'dotnet format' to fix analyzers issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj &&
dotnet build --no-restore ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
- name: Setup InfluxDB
uses: influxdata/influxdb-action@v3
with:
influxdb_version: latest
influxdb_org: influxdata
influxdb_user: ci_user
influxdb_password: password
influxdb_bucket: dummy
- name: Test
run: dotnet test --no-restore --no-build ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
2,013 changes: 1,015 additions & 998 deletions AspNetCore.Diagnostics.HealthChecks.sln

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[![GremlinDb Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_gremlin_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_gremlin_ci.yml)
[![Hangfire Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_hangfire_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_hangfire_ci.yml)
[![IbmMQ Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_ibmmq_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_ibmmq_ci.yml)
[![InfluxDB Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_influxdb_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_influxdb_ci.yml)
[![Kafka Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_kafka_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_kafka_ci.yml)
[![MongoDb Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_mongodb_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_mongodb_ci.yml)
[![MySql Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_mysql_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_mysql_ci.yml)
Expand Down Expand Up @@ -123,6 +124,7 @@ HealthChecks packages include health checks for:
| Gremlin | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Gremlin)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Gremlin) |
| Hangfire | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Hangfire)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Hangfire) |
| IbmMQ | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.IbmMQ)](https://www.nuget.org/packages/AspNetCore.HealthChecks.IbmMQ) |
| InfluxDB | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.InfluxDB)](https://www.nuget.org/packages/AspNetCore.HealthChecks.InfluxDB) |
| Kafka | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Kafka)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Kafka) |
| Kubernetes | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Kubernetes)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Kubernetes) |
| MongoDB | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.MongoDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.MongoDb) |
Expand Down Expand Up @@ -169,6 +171,7 @@ Install-Package AspNetCore.HealthChecks.Gcp.CloudFirestore
Install-Package AspNetCore.HealthChecks.Gremlin
Install-Package AspNetCore.HealthChecks.Hangfire
Install-Package AspNetCore.HealthChecks.IbmMQ
Install-Package AspNetCore.HealthChecks.InfluxDB
Install-Package AspNetCore.HealthChecks.Kafka
Install-Package AspNetCore.HealthChecks.Kubernetes
Install-Package AspNetCore.HealthChecks.MongoDb
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using HealthChecks.InfluxDB;
using InfluxDB.Client;
using Microsoft.Extensions.Diagnostics.HealthChecks;

maikebing marked this conversation as resolved.
Show resolved Hide resolved
namespace Microsoft.Extensions.DependencyInjection;

public static class InfluxDBHealthCheckBuilderExtensions
{
private const string NAME = "influxdb";

/// <summary>
/// Add a health check for InfluxDB services using connection string.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="connectionString">The InfluxDB connection string to be used.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'influxdb' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
public static IHealthChecksBuilder AddInfluxDB(this IHealthChecksBuilder builder, string connectionString, string? name = default, HealthStatus? failureStatus = default, IEnumerable<string>? tags = default, TimeSpan? timeout = default)
{
builder.Services
.AddSingleton(sp => new InfluxDBHealthCheck(builder => builder.ConnectionString(connectionString).Build()));

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => sp.GetRequiredService<InfluxDBHealthCheck>(),
failureStatus,
tags,
timeout));
}

/// <summary>
/// Add a health check for InfluxDB services using connection string.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="uri">The InfluxDB connection string to be used.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'influxdb' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
public static IHealthChecksBuilder AddInfluxDB(this IHealthChecksBuilder builder, Uri uri, string? name = default, HealthStatus? failureStatus = default, IEnumerable<string>? tags = default, TimeSpan? timeout = default)
{
builder.Services
.AddSingleton(sp => new InfluxDBHealthCheck(builder => builder.Url(uri.ToString()).Build()));

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => sp.GetRequiredService<InfluxDBHealthCheck>(),
failureStatus,
tags,
timeout));
}

maikebing marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Add a health check for InfluxDB services using url with token.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="url"></param>
/// <param name="token"></param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'influxdb' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>

/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
public static IHealthChecksBuilder AddInfluxDB(this IHealthChecksBuilder builder, string url, string token, string? name = default, HealthStatus? failureStatus = default, IEnumerable<string>? tags = default, TimeSpan? timeout = default)
{
builder.Services
.AddSingleton(sp => new InfluxDBHealthCheck(builder => builder.Url(url).AuthenticateToken(token.ToArray()).Build()));

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => sp.GetRequiredService<InfluxDBHealthCheck>(),
failureStatus,
tags,
timeout));
}

/// <summary>
/// Add a health check for InfluxDB services using url.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="url"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'InfluxDB' will be used for the name.</param>
maikebing marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param>
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
public static IHealthChecksBuilder AddInfluxDB(this IHealthChecksBuilder builder, string url, string username, string password, string? name = default, HealthStatus? failureStatus = default, IEnumerable<string>? tags = default, TimeSpan? timeout = default)
{
builder.Services
.AddSingleton(sp => new InfluxDBHealthCheck(builder => builder.Url(url).Authenticate(username, password.ToArray()).Build()));

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => sp.GetRequiredService<InfluxDBHealthCheck>(),
failureStatus,
tags,
timeout));
}

/// <summary>
/// Add a health check for InfluxDB services using <see cref="InfluxDBClient"/> from service provider.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'influxdb' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param>
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
public static IHealthChecksBuilder AddInfluxDB(this IHealthChecksBuilder builder, string? name = default, HealthStatus? failureStatus = default, IEnumerable<string>? tags = default, TimeSpan? timeout = default)
{
builder.Services.AddSingleton(sp => new InfluxDBHealthCheck(sp.GetRequiredService<InfluxDBClient>()));
return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => sp.GetRequiredService<InfluxDBHealthCheck>(),
failureStatus,
tags,
timeout));
}
}
16 changes: 16 additions & 0 deletions src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageTags>HealthCheck;Health;InfluxDB</PackageTags>
<Description>HealthChecks.InfluxDB is the health check package for InfluxDB.</Description>
<VersionPrefix>$(HealthCheckInfluxDB)</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="InfluxDB.Client" Version="4.9.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.1" />
<Compile Include="../HealthCheckResultTask.cs" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions src/HealthChecks.InfluxDB/InfluxDBHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using InfluxDB.Client;
using InfluxDB.Client.Api.Domain;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.InfluxDB;

public class InfluxDBHealthCheck : IHealthCheck, IDisposable
{
private readonly InfluxDBClient _influxdb_client;
maikebing marked this conversation as resolved.
Show resolved Hide resolved

maikebing marked this conversation as resolved.
Show resolved Hide resolved
public InfluxDBHealthCheck(Func<InfluxDBClientOptions.Builder, InfluxDBClientOptions> _options)
{
_influxdb_client = new InfluxDBClient(_options.Invoke(InfluxDBClientOptions.Builder.CreateNew()));
}

public InfluxDBHealthCheck(InfluxDBClient influxDBClient)
{
_influxdb_client = influxDBClient;
}

maikebing marked this conversation as resolved.
Show resolved Hide resolved
/// <inheritdoc />
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
var ready = await _influxdb_client.ReadyAsync();
var ping = await _influxdb_client.PingAsync();
return ping && ready.Status == Ready.StatusEnum.Ready
? HealthCheckResult.Healthy()
: new HealthCheckResult(context.Registration.FailureStatus, $"Status:{ready.Status} Started:{ready.Started} Up:{ready.Up}");
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}

public void Dispose() => _influxdb_client.Dispose();
}
40 changes: 40 additions & 0 deletions src/HealthChecks.InfluxDB/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# InfluxDB Health Check
maikebing marked this conversation as resolved.
Show resolved Hide resolved

This health check verifies the ability to communicate with a InfluxDB server.

## Example Usage

With all of the following examples, you can additionally add the following parameters:

- `name`: The health check name. Default if not specified is `influxdb`.
- `failureStatus`: The `HealthStatus` that should be reported when the health check fails. Default is `HealthStatus.Unhealthy`.
- `tags`: A list of tags that can be used to filter sets of health checks.
- `timeout`: A `System.TimeSpan` representing the timeout of the check.

### Basic

This will create a new `InfluxDBClient` and reuse it on every request to get the health check result. Use
the extension method where you provide the `Uri` to connect with.

```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthChecks()
.AddInfluxDB("http://localhost:8086/?org=iotsharp&bucket=iotsharp-bucket&token=iotsharp-token");
}
```

If you are sharing a single `InfluxDBClient` for every time a health check is requested,
you must ensure automatic recovery is enabled so that the `InfluxDBClient` can be re-established if lost.

```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<InfluxDBClient>(sp =>
{
return InfluxDBClientFactory.Create("http://localhost:8086/?org=iotsharp&bucket=iotsharp-bucket&token=iotsharp-token");
})
.AddHealthChecks()
.AddInfluxDB();
}
```
Loading