Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 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
0936b95
Merge branch 'development' into fixResolve
Aug 20, 2025
3b436b6
Merge branch 'fixResolve'
Aug 20, 2025
ddd334c
Merge branch 'development' into influxdbConnector
Umang01-hash Aug 25, 2025
1fd9cae
[revert] container mocks (not relevent to my PR)
akhilsharmaa Aug 27, 2025
b9b8813
Merge branch 'development' into influxdbConnector
akhilsharmaa Aug 27, 2025
9437e09
change path of the interface mock code to same folder.
akhilsharmaa Aug 27, 2025
86f1e07
Merge remote-tracking branch 'refs/remotes/origin/influxdbConnector'
akhilsharmaa Aug 27, 2025
c9b8702
[Fixed linting]
akhilsharmaa Aug 27, 2025
d6e1192
Merge branch 'development' into influxdbConnector
Umang01-hash Aug 29, 2025
3a5b76b
Merge branch 'development' into influxdbConnector
akhilsharmaa Aug 29, 2025
b70ba41
Merge branch 'development' into influxdbConnector
Umang01-hash Sep 1, 2025
5b7d5b3
Merge branch 'development' into influxdbConnector
Umang01-hash Sep 1, 2025
58dab37
Merge branch 'development' into influxdbConnector
Umang01-hash Sep 2, 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
128 changes: 128 additions & 0 deletions docs/datasources/influxdb/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# 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 {
app.Logger().Debug(err)
return
}
app.Logger().Debug("InfluxDB connected: ", ok)

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

// List organizations
orgs, _ := client.ListOrganization(context.Background())
app.Logger().Debug("Organizations: ")
for id, name := range orgs {
app.Logger().Debug(id, name)
}

// Create bucket
bucketID, err := client.CreateBucket(context.Background(), orgID, "demo-bucket")
if err != nil {
app.Logger().Debug(err)
return
}

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

// Delete bucket
if err := client.DeleteBucket(context.Background(), bucketID); err != nil {
app.Logger().Debug(err)
return
}
app.Logger().Debug("Bucket deleted successfully")

// Delete organization
if err := client.DeleteOrganization(context.Background(), orgID); err != nil {
app.Logger().Debug(err)
return
}
app.Logger().Debug("Organization deleted successfully")
// Start the server
app.Run()
}
```
5 changes: 5 additions & 0 deletions docs/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ export const navigation = [
href: "/docs/datasources/elasticsearch",
desc: "Learn how to connect to and interact with elasticsearch in GoFr."
},
{
title: "InfluxDB",
href: "/docs/datasources/influxdb",
desc: "Learn how to connect to and interact with influxdb in GoFr."
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ use (
./pkg/gofr/datasource/scylladb
./pkg/gofr/datasource/solr
./pkg/gofr/datasource/surrealdb
pkg/gofr/datasource/influxdb
)
114 changes: 102 additions & 12 deletions go.work.sum

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/gofr/cmd/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestRequest_Bind(t *testing.T) {

osHostName, _ := os.Hostname()

//nolint:usetesting // Comparing context.Background() directly is intentional and safe in this case.
Copy link
Member

Choose a reason for hiding this comment

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

Why this is being removed? It will give us a linter error and it is also not in the scope of this PR. Please revert these changes back.

assert.Equal(t, context.Background(), ctx, "TEST Failed.\n context is not context.Background.")

assert.Equal(t, osHostName, hostName, "TEST Failed.\n Hostname did not match.")
Expand Down
1 change: 1 addition & 0 deletions pkg/gofr/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Container struct {
Elasticsearch Elasticsearch
Oracle OracleDB
Couchbase Couchbase
InfluxDB InfluxDB

KVStore KVStore

Expand Down
46 changes: 46 additions & 0 deletions pkg/gofr/container/datasources.go
Copy link
Member

Choose a reason for hiding this comment

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

So we also have a mock container. I would need you to generate InFluxDB mocks and add it there.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"database/sql"
"time"

"github.com/redis/go-redis/v9"

Expand Down Expand Up @@ -776,3 +777,48 @@ type CouchbaseProvider interface {

provider
}

// InfluxDB defines the operations required to interact with an InfluxDB instance.
type InfluxDB interface {
// CreateOrganization create new bucket in the influxdb
CreateOrganization(ctx context.Context, org string) (string, error)

// DeleteOrganization deletes a organization under the specified organization.
DeleteOrganization(ctx context.Context, orgID string) error

// ListOrganization list all the available organization
ListOrganization(ctx context.Context) (orgs map[string]string, err error)

// WritePoint writes one time-series points to a bucket.
// 'points' should follow the line protocol format or structured map format.
WritePoint(ctx context.Context, org, bucket string,
measurement string,
tags map[string]string,
fields map[string]any,
timestamp time.Time) error

// Query runs a Flux query and returns the result as a slice of maps,
// where each map is a row with column name-value pairs.
Query(ctx context.Context, fluxQuery string) ([]map[string]any, error)

// CreateBucket creates a new bucket under the specified organization.
CreateBucket(ctx context.Context, org, bucket string) (string, error)

// DeleteBucket deletes a bucketId with bucketID
DeleteBucket(ctx context.Context, bucketID string) error

// ListBuckets lists all buckets under the specified organization.
ListBuckets(ctx context.Context, org string) (map[string]string, error)

// Ping checks if the InfluxDB instance is reachable and healthy.
Ping(ctx context.Context) (bool, error)

HealthChecker
}

// InfluxDBProvider an interface that extends InfluxDB with additional methods for logging, metrics, and connection management.
type InfluxDBProvider interface {
InfluxDB

provider
}
1 change: 1 addition & 0 deletions pkg/gofr/container/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func checkExternalDBHealth(ctx context.Context, c *Container, healthMap map[stri
"elasticsearch": c.Elasticsearch,
"oracle": c.Oracle,
"couchbase": c.Couchbase,
"influx": c.InfluxDB,
}

for name, service := range services {
Expand Down
Loading