Skip to content

Conversation

akhilsharmaa
Copy link

@akhilsharmaa akhilsharmaa commented Jul 17, 2025

InfluxDB Connector for GoFr

Closes: #1994

Contributor: Akhilesh Kumar Sharma
Track: Core Framework

Overview

This PR introduces native support for InfluxDB, a widely-used time-series database, to GoFr. With this integration, GoFr can now seamlessly store and query high-frequency data such as metrics and sensor data, enhancing its capabilities for time-series workloads.

Problem

Currently, GoFr does not support InfluxDB, which restricts its ability to effectively manage time-series data. This integration addresses that limitation by adding the necessary functionality.

Scope

The following changes and features have been implemented in this PR:

  • Added an InfluxDB datasource in pkg/gofr/datasource/influxdb.
  • Introduced a method on App to utilize the datasource.
  • Implemented logging for operations and failures to aid in debugging and monitoring.

Checklist

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

@gizmo-rt gizmo-rt added the enhancement New feature or request label Jul 17, 2025
@coolwednesday coolwednesday changed the title [GoFr-SOC]: InfluxDB Connector for GoFr InfluxDB Connector for GoFr Jul 21, 2025
Copy link
Member

@Umang01-hash Umang01-hash left a comment

Choose a reason for hiding this comment

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

  • Create a separate go.mod for pkg/gofr.datasource/influxdb and please make sure no unnecessary imports are added to GoFr's go.mod.
  • No test files added. Please make sure to try and achieve atleast 80-85% code coverage in the newly added directory influxdb.
  • GoDoc comments are not proper and lacks info about the method.
  • Your newly added code has a lot of linter errors in pkg/gofr/datasource/influxdb. Please address and resolve them.
  • The file interfaces.go is empty. If you don;t need it you can delete it but i think you need it for testing and other purposes. Please refer to other datasources and you will understand.
  • Let's add screenshots for InfluxDB logs and queries to see how they look after pretty printed.

@akhilsharmaa
Copy link
Author

@Umang01-hash thanks for the review, i am working on it.

@akhilsharmaa
Copy link
Author

akhilsharmaa commented Jul 29, 2025

@Umang01-hash please run the CI, i have written the test and fixed the linting issue, let's see, also achieved the the 72% coverage in influxdb. also I haven't mocked the influxdb, maybe that's why coverage is low, please let me know if i'ts required to mock that. (actually, i'm new to mocking), also review the PR.

@akhilsharmaa
Copy link
Author

akhilsharmaa commented Jul 29, 2025

please rerun @Umang01-hash

Copy link
Member

@coolwednesday coolwednesday left a comment

Choose a reason for hiding this comment

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

@akhilsharmaa, After doing the review changes. Please add a screenshot of the running server with DB Calls with proper logs, traces and metrics.

Please also add the docker command to setup an db instance in the contributing.md as well as docs for developer's ease of setup for exploring and testing as well.

Thank You !

Well Done : )

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.

Copy link
Member

Choose a reason for hiding this comment

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

Do refer to SendOperationStats method in other datasources that adds traces and metrics in the respective datasources' methods. We would need you to also add them.

Comment on lines +314 to +324
func (c *Client) UseLogger(logger any) {
if l, ok := logger.(Logger); ok {
c.logger = l
}
}

func (c *Client) UseMetrics(metrics any) {
if m, ok := metrics.(Metrics); ok {
c.metrics = m
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It should not be any as the parameter. Refer to mongo datasource for method signature and modify this accordingly.

@akhilsharmaa
Copy link
Author

@akhilsharmaa, After doing the review changes. Please add a screenshot of the running server with DB Calls with proper logs, traces and metrics.

Please also add the docker command to setup an db instance in the contributing.md as well as docs for developer's ease of setup for exploring and testing as well.

Thank You !

Well Done : )

Thanks, i am working on the changes.

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()

Comment on lines +27 to +29
UseLogger(logger any)
UseMetrics(metrics any)
UseTracer(tracer any)
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.

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.

@coolwednesday
Copy link
Member

@akhilsharmaa , Logging , metrics, traces have not been added. Refer to mongo datasource package or this PR : #2076, for reference.

@Umang01-hash
Copy link
Member

@akhilsharmaa There are quite a few merge conflicts in your PR. I strongly recommend pulling the latest changes from the development branch regularly and resolving conflicts as they arise. Delaying this may lead to more complex and extensive code changes later on.

@akhilsharmaa
Copy link
Author

@akhilsharmaa There are quite a few merge conflicts in your PR. I strongly recommend pulling the latest changes from the development branch regularly and resolving conflicts as they arise. Delaying this may lead to more complex and extensive code changes later on.

@Umang01-hash thanks, i have resolved the conflicts, waiting for the review. :)

Copy link
Member

@Umang01-hash Umang01-hash left a comment

Choose a reason for hiding this comment

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

Hey @akhilsharmaa here are a few key changes for your PR:

  • The current doucmentation inside docs/datasources/influxdb is nice but we try to maintain consistency with other datasource documentations. Please refer to any other datasource doucmentation (ex: mongo/cassandra). You currently have extra methods and the starting should also be improved.
  • The file mock_container.go has major errors and unintentional changes. Please resolve them (Unresolved reference 'dgraphMock', Unresolved reference 'opentsdbMock' etc.) These changes were also not related to your PR so please revert them back and add only influxdb mock where needed in mock container.
  • The file mock_interface.go should be placed outside of the mocks directory inside datasource/influxdb. No need to create mocks directory inside influxdb.
  • As far as i can see the influxdb has currently only logs but no metrics and traces. You can refer to other datasources to see how are these added. (Look at method sendOperationStats)
  • All the methods that you have listed inside datasource/influxdb/interface.go (27 methods) are not same as the one you declared inside container/datasources.go (9 methods). You need to figure it out and try to place a nearly similar interface there too to maintain consistency.
  • Also i am not getting the use of influxdb/internal.go. Can you please put some light on it.
  • You should also add test for AddInfluxDB added in external_db.go.
  • Currently your code quality pipeline is failing and it may be due to errors in mock_container.go so once you fix that please recheck on any linter errors.

Copy link
Author

@akhilsharmaa akhilsharmaa Aug 27, 2025

Choose a reason for hiding this comment

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

@Umang01-hash , This internal is just wrappers, main purpose was to clean implementation of mocking. (instead of generating all the functions of deafault interface, just wrapper it).

@akhilsharmaa
Copy link
Author

akhilsharmaa commented Aug 28, 2025

  • The current doucmentation inside docs/datasources/influxdb is nice but we try to maintain consistency with other datasource documentations. Please refer to any other datasource doucmentation (ex: mongo/cassandra). You currently have extra methods and the starting should also be improved.

WIP

  • The file mock_container.go has major errors and unintentional changes. Please resolve them (Unresolved reference 'dgraphMock', Unresolved reference 'opentsdbMock' etc.) These changes were also not related to your PR so please revert them back and add only influxdb mock where needed in mock container.

i have resolved, please confirm it once.

  • The file mock_interface.go should be placed outside of the mocks directory inside datasource/influxdb. No need to create mocks directory inside influxdb.\

yes, i have moved it now.

  • As far as i can see the influxdb has currently only logs but no metrics and traces. You can refer to other datasources to see how are these added. (Look at method sendOperationStats)

yes, will implement it soon.

  • All the methods that you have listed inside datasource/influxdb/interface.go (27 methods) are not same as the one you declared inside container/datasources.go (9 methods). You need to figure it out and try to place a nearly similar interface there too to maintain consistency.

Actually datasource/influxdb/interface.go interface don't have any other purpose then mocking influxdb, so that's why this have 27 method (actually all methods are currently used by tests.)

  • Also i am not getting the use of influxdb/internal.go. Can you please put some light on it.

This internal is just wrappers, main purpose was to clean implementation of mocking. (instead of generating all the functions of deafault interface, just wrapper it).

  • You should also add test for AddInfluxDB added in external_db.go.
  • Currently your code quality pipeline is failing and it may be due to errors in mock_container.go so once you fix that please recheck on any linter errors.

Fixed :)

@akhilsharmaa
Copy link
Author

akhilsharmaa commented Aug 29, 2025

@Umang01-hash please run the workflow, seems pipline is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants