Skip to content

InfluxDB Connector for GoFr #2072

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

Open
wants to merge 43 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7eab5de
[interfaces] InfluxDBProvider, InfluxDB interface added with all the …
akhilsharmaa Jul 5, 2025
495cca8
[healthcheck] function implemented for the healthcheck of influxdb cl…
akhilsharmaa Jul 7, 2025
d12d464
[ListBuckets] function implemented, user can get the all the bucket b…
akhilsharmaa Jul 11, 2025
359e1d3
[implementation] CreateOrganization, DeleteOrganization, DeleteOrgani…
akhilsharmaa Jul 13, 2025
1b287d3
useMetrics, useLogger, useTracer implemented.
akhilsharmaa Jul 15, 2025
b926361
[docs] documentation for the influxdb and example for using this.
akhilsharmaa Jul 15, 2025
725354d
[test+comments] Added the tests and proper comments, current coverage…
akhilsharmaa Jul 22, 2025
f5c1422
[refactor] using predefined errors, for consistent errors.
akhilsharmaa Jul 22, 2025
5069344
[tests] Unit test for Creating and Deleting Organization.
akhilsharmaa Jul 24, 2025
e4d573f
[tests] Unit test for Buckets operation written, achieving 72% coverage.
akhilsharmaa Jul 24, 2025
080eb8f
[write, query] implemented functions of influxdb to insert data & per…
akhilsharmaa Jul 27, 2025
9cf1c3d
[test] added test for the write and query on influxdb.
akhilsharmaa Jul 27, 2025
5896876
[linting] fixed various linting errors
akhilsharmaa Jul 29, 2025
b544346
[linting] fixed some linting errors
akhilsharmaa Jul 29, 2025
e2b7d69
[fixed-linting] all linting errors fixed.
akhilsharmaa Jul 29, 2025
aabc2b5
[fixed-linting] all linting errors fixed.
akhilsharmaa Jul 29, 2025
2090fc1
[fixed-linting] container linting errors fixed.
akhilsharmaa Jul 29, 2025
68b2ab8
Merge branch 'development' into influxdbConnector
Umang01-hash Jul 31, 2025
06d9a6f
[fixed-linting] some linting issues fixed.
akhilsharmaa Jul 31, 2025
e2e4a8f
Merge remote-tracking branch 'origin/influxdbConnector' into influxdb…
akhilsharmaa Jul 31, 2025
ad1116c
[mocking] mocking metrics + logger
akhilsharmaa Aug 4, 2025
9befb08
[removed] docker-compose.yml (was just experiment)
akhilsharmaa Aug 4, 2025
1588bf7
[fix] metric + tracer added.
akhilsharmaa Aug 5, 2025
2f0e55f
[mock] influx client for mock tests.
akhilsharmaa Aug 6, 2025
14b3048
[mock] health Success + Fail (both completed) Ping test completed.
akhilsharmaa Aug 7, 2025
6b549db
[tests] createOrganization tests added, checking conditions of empty,…
akhilsharmaa Aug 7, 2025
91d4b2f
[tests] Test_DeleteOrganization tests added, checking conditions of e…
akhilsharmaa Aug 7, 2025
de341d3
Merge branch 'development' into influxdbConnector
coolwednesday Aug 7, 2025
cb68b3d
[tests] Test_ListOrganization tests added for checking conditions of …
akhilsharmaa Aug 7, 2025
f2002ac
Merge branch 'listorganizationTest' into influxdbConnector
akhilsharmaa Aug 7, 2025
f8bc4c4
[tests] Test_CreateBucket tests added. Currently coverage - 47% .
akhilsharmaa Aug 7, 2025
dcafa99
[tests] Test_DeleteBucket tests added. Currently coverage - 48% .
akhilsharmaa Aug 7, 2025
c2e7036
[tests] Test_ListBucket tests added. coverage - 54.3% .
akhilsharmaa Aug 7, 2025
be1f3f5
[file delete] old test file deleted, which was not mocking the influx…
akhilsharmaa Aug 7, 2025
70933b7
[linting] fixed linting issues.
akhilsharmaa Aug 7, 2025
8859e29
[tests] Test_Query tests added. coverage - 57.1% .
akhilsharmaa Aug 8, 2025
cb85903
[docs] added index in navigation.
akhilsharmaa Aug 10, 2025
e797747
[logger] fixed , using app logger instead of fmt.
akhilsharmaa Aug 11, 2025
b1e3086
[logger] fixed , using app logger instead of fmt.
akhilsharmaa Aug 11, 2025
f2b8ab8
Merge branch 'development' into influxdbConnector
Umang01-hash Aug 12, 2025
5262ff0
[minimized] InfluxClient inteface got rid of extra function which are…
akhilsharmaa Aug 12, 2025
e6038ed
[refactor] coverage completed, getting 41% coverage.
akhilsharmaa Aug 14, 2025
3a21868
[tests] added tests for the Buckets, 50% coverrage.
akhilsharmaa Aug 14, 2025
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
129 changes: 129 additions & 0 deletions docs/datasources/influxdb/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# InfluxDB
GoFr supports injecting InfluxDB using an interface that defines the necessary methods to interact with InfluxDB v2+.
Any driver that implements this interface can be injected via the `app.AddInfluxDB()` method.

---

## Interface

```go
// InfluxDB defines the methods for interacting with an InfluxDB database.
type InfluxDB interface {
Connect()
CreateOrganization(ctx context.Context, orgName string) (string, error)
DeleteOrganization(ctx context.Context, orgID string) error
ListOrganization(ctx context.Context) (map[string]string, error)

CreateBucket(ctx context.Context, orgID string, bucketName string, retentionPeriod time.Duration) (string, error)
DeleteBucket(ctx context.Context, orgID, bucketID string) error
ListBuckets(ctx context.Context, org string) (map[string]string, error)

Ping(ctx context.Context) (bool, error)
HealthCheck(ctx context.Context) (any, error)

Query(ctx context.Context, org string, fluxQuery string) ([]map[string]any, error)
WritePoints(ctx context.Context, bucket string, org string, points []container.InfluxPoint) error)

UseLogger(logger any)
UseMetrics(metrics any)
UseTracer(tracer any)
Comment on lines +27 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exposed to user. Refer to mongoDB datasource addition for more info.

}
```

This structure supports all essential InfluxDB operations including organization/bucket management, health checks, and metrics ingestion.

Import the gofr's external driver for influxdb:

```bash
go get gofr.dev/pkg/gofr/datasource/influxdb@latest
```

## Example
```go
package main

import (
"context"
"fmt"
"time"

"gofr.dev/pkg/gofr"
"gofr.dev/pkg/gofr/datasource/influxdb"
)

func main() {

// Create a new GoFr application
app := gofr.New()

// Initialize InfluxDB client
client := influxdb.New(influxdb.Config{
Url: "http://localhost:8086",
Username: "admin",
Password: "admin1234",
Token: "<your-token>",
})

// Add InfluxDB to application context
app.AddInfluxDB(client)

// Sample route
app.GET("/greet", func(ctx *gofr.Context) (any, error) {
return "Hello World!", nil
})

// Ping InfluxDB
ok, err := client.Ping(context.Background())
if err != nil {
fmt.Println("Ping failed:", err)
return
}
fmt.Println("InfluxDB connected:", ok)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use app.logger()


// Create organization
orgID, err := client.CreateOrganization(context.Background(), "demo-org")
if err != nil {
fmt.Println("CreateOrganization error:", err)
return
}

// List organizations
orgs, _ := client.ListOrganization(context.Background())
fmt.Println("Organizations:")
for id, name := range orgs {
fmt.Printf("- %s: %s\n", id, name)
}

// Create bucket
bucketID, err := client.CreateBucket(context.Background(), orgID, "demo-bucket", time.Hour)
if err != nil {
fmt.Println("CreateBucket error:", err)
return
}

// List buckets for organization
buckets, err := client.ListBuckets(context.Background(), "demo-org")
if err != nil {
fmt.Println("ListBuckets error:", err)
return
}
fmt.Println("Buckets:", buckets)

// Delete bucket
if err := client.DeleteBucket(context.Background(), orgID, bucketID); err != nil {
fmt.Println("DeleteBucket error:", err)
return
}
fmt.Println("Bucket deleted successfully")

// Delete organization
if err := client.DeleteOrganization(context.Background(), orgID); err != nil {
fmt.Println("DeleteOrganization error:", err)
return
}
fmt.Println("Organization deleted successfully")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a setup function .... pseudo and then make REST endpoints for adding, retrieving data.

// Start the server
app.Run()
}
```
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/influxdata/influxdb-client-go/v2 v2.14.0
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
Expand All @@ -25,6 +26,7 @@ require (
github.com/redis/go-redis/v9 v9.10.0
github.com/segmentio/kafka-go v0.4.48
github.com/stretchr/testify v1.10.0
go.opencensus.io v0.24.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.61.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0
go.opentelemetry.io/otel v1.36.0
Expand Down Expand Up @@ -53,6 +55,7 @@ require (
cloud.google.com/go/compute/metadata v0.7.0 // indirect
cloud.google.com/go/iam v1.5.2 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -68,10 +71,12 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.14.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -86,7 +91,6 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.einride.tech/aip v0.68.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.36.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/XSAM/otelsql v0.39.0 h1:4o374mEIMweaeevL7fd8Q3C710Xi2Jh/c8G4Qy9bvCY=
github.com/XSAM/otelsql v0.39.0/go.mod h1:uMOXLUX+wkuAuP0AR3B45NXX7E9lJS2mERa8gqdU8R0=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
Expand Down Expand Up @@ -117,8 +121,13 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDa
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
github.com/influxdata/influxdb-client-go/v2 v2.14.0 h1:AjbBfJuq+QoaXNcrova8smSjwJdUHnwvfjMF71M1iI4=
github.com/influxdata/influxdb-client-go/v2 v2.14.0/go.mod h1:Ahpm3QXKMJslpXl3IftVLVezreAUtBOTZssDrjZEFHI=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
Expand All @@ -145,6 +154,8 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo=
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
Expand Down Expand Up @@ -182,6 +193,7 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/segmentio/kafka-go v0.4.48 h1:9jyu9CWK4W5W+SroCe8EffbrRZVqAOkuaLd/ApID4Vs=
github.com/segmentio/kafka-go v0.4.48/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
Loading