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

feat: Add RedisTimeSeries plugin #11054

Merged
merged 24 commits into from Jul 19, 2022
Merged

feat: Add RedisTimeSeries plugin #11054

merged 24 commits into from Jul 19, 2022

Conversation

gkorland
Copy link
Contributor

@gkorland gkorland commented May 1, 2022

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@gkorland gkorland mentioned this pull request May 1, 2022
3 tasks
@gkorland
Copy link
Contributor Author

gkorland commented May 1, 2022

@srebhan
Followup on - #5275 (review)

  •  The formatting of the sampleConfig and the corresponding update in the README.
    

Done.

  •  The superfluous length check for metrics in Write().
    

Done

  •  Check for address being actually set before constructing the client and report an error if it is not.
    

Done

  •  A comment to my question regarding using a mock-package to test this plugin without requiring a real database instance.
    

I'm not familiar of RedisTimeSeries mock for Go.

  •  Newly added comment regarding simplification in Write().
    

Done, also removed the uneeded retry, FT.ADD can create a series if doesn't exist already.

@gkorland gkorland changed the title add support for RedisTimeSeries plugin Add support for RedisTimeSeries plugin May 1, 2022
Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for the nice update @gkorland! I do have only some style suggestions, but the PR looks good overall. There are two more things I want to ask you:

  1. Please sync the README example with the sampleConfig to show all options to the user.
  2. Can you please add a test for the serialization? You can fake a client by introducing an interface with a Do() function and then compare the serialized format to the expected one. This would give us at least some testing in short-mode.

plugins/outputs/redistimeseries/README.md Show resolved Hide resolved
plugins/outputs/redistimeseries/README.md Outdated Show resolved Hide resolved
plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
gkorland and others added 7 commits May 9, 2022 11:47
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

This only leaves us with synchronizing the sampleConfig to the README example...

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@gkorland we are almost there. I would comment the optional options (as this is what we do everywhere else). Furthermore, there is a closing quote missing in your TOML section...

plugins/outputs/redistimeseries/README.md Outdated Show resolved Hide resolved
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for keep rocking on this PR @gkorland!

@srebhan
Copy link
Contributor

srebhan commented May 25, 2022

@gkorland it seems like there are some merge conflicts. Can you please rebase this PR on the latest master and resolve the conflicts!?

@srebhan srebhan changed the title Add support for RedisTimeSeries plugin feat: Add RedisTimeSeries plugin May 25, 2022
Copy link
Contributor

@MyaLongmire MyaLongmire left a comment

Choose a reason for hiding this comment

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

Just one small question and we will be good to go! Thank you for your work on this :)

Can you also run go mod tidy and check back in as that should make the tests pass?

etc/telegraf.conf Show resolved Hide resolved
plugins/inputs/redis/redis.go Outdated Show resolved Hide resolved
@chayim
Copy link

chayim commented Jun 7, 2022

Pushed!

@srebhan
Copy link
Contributor

srebhan commented Jun 9, 2022

@chayim and @gkorland I see the tests failing. This is probably due to an update of the redis libraries. Can you maybe take a look?

@thallredis
Copy link

@chayim can you look at the failing test?

@chayim
Copy link

chayim commented Jun 28, 2022

@srebhan I've fixed the merge conflicts, and our code, it passes all of CI, except for the Windows issue in statsd. But, given that this is a timeout.. perhaps it's a red herring? Can you please advise?

@sspaink sspaink added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jun 28, 2022
Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Can you please fix the error text? Other than this, the PR looks good.

plugins/outputs/redistimeseries/redistimeseries.go Outdated Show resolved Hide resolved
@@ -0,0 +1,26 @@
package redistimeseries
Copy link
Contributor

Choose a reason for hiding this comment

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

As there is zero testing in this PR that would get routinely run, I'd like to see an integration test.

There is an example in the redis input using testcontainers that you can copy and paste from.

Copy link

Choose a reason for hiding this comment

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

@powersj Maybe I misunderstand the testing (and likely)! But doesn't the TestConnectAndWrite in this file, with the MockMetrics cover this use case? I'd like to make sure I'm not missing something - and I'm pretty sure I am.

Copy link
Contributor

Choose a reason for hiding this comment

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

The point is that you have only a single test and this test isn't run by default (see if testing.Short() { ...Skip...}) as it requires a local instance of redis running. @powersj added some infrastructure to enable integration tests using testcontainers (aka docker images) to verify functionality of plugins.

So the request is to make use of this infrastructure (see the plugin linked above) to at least enable integration tests for your plugin...

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@srebhan
Copy link
Contributor

srebhan commented Jul 4, 2022

@gkorland, @chayim can you please fix the CI issue and address the comment of @powersj?

Comment on lines +9 to +26
func TestConnectAndWrite(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

address := testutil.GetLocalHost() + ":6379"
redis := &RedisTimeSeries{
Address: address,
}

// Verify that we can connect to the RedisTimeSeries server
err := redis.Connect()
require.NoError(t, err)

// Verify that we can successfully write data to the RedisTimeSeries server
err = redis.Write(testutil.MockMetrics())
require.NoError(t, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To allow integration tests you want something like this

Suggested change
func TestConnectAndWrite(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
address := testutil.GetLocalHost() + ":6379"
redis := &RedisTimeSeries{
Address: address,
}
// Verify that we can connect to the RedisTimeSeries server
err := redis.Connect()
require.NoError(t, err)
// Verify that we can successfully write data to the RedisTimeSeries server
err = redis.Write(testutil.MockMetrics())
require.NoError(t, err)
}
func TestConnectAndWriteIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
servicePort := "6379"
container := testutil.Container{
Image: "redis:alpine",
ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
}
require.NoError(t, container.Start(), "failed to start container")
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()
redis := &RedisTimeSeries{
Address: fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort]),
}
// Verify that we can connect to the RedisTimeSeries server
require.NoError(t, redis.Connect())
// Verify that we can successfully write data to the RedisTimeSeries server
require.NoError(t, redis.Write(testutil.MockMetrics()))
}

@powersj
Copy link
Contributor

powersj commented Jul 18, 2022

Hi @chayim - @srebhan and I talked and he will write the integration test once this is merged. It is something he wanted to learn anyway.

Can you resolve the test issues and we can land this? Looks like a complaint:

vet: plugins/outputs/redistimeseries/redistimeseries.go:40:10: undeclared name: errors

You should be able to reproduce locally with make check

Thanks!

@chayim
Copy link

chayim commented Jul 19, 2022

You should be able to reproduce locally with make check

Yes... especially since that was already there, and I just needed to push. Pushing @powersj

@telegraf-tiger
Copy link
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

🥳 This pull request decreases the Telegraf binary size by -2.02 % for linux amd64 (new size: 143.3 MB, nightly size 146.2 MB)

📦 Click here to get additional PR build artifacts

Artifact URLs

DEB RPM TAR GZ ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm darwin_arm64.tar.gz windows_i386.zip
armel.deb armv6hl.rpm freebsd_amd64.tar.gz
armhf.deb i386.rpm freebsd_armv7.tar.gz
i386.deb ppc64le.rpm freebsd_i386.tar.gz
mips.deb riscv64.rpm linux_amd64.tar.gz
mipsel.deb s390x.rpm linux_arm64.tar.gz
ppc64el.deb x86_64.rpm linux_armel.tar.gz
riscv64.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz
static_linux_amd64.tar.gz

@powersj powersj merged commit 3c5d71b into influxdata:master Jul 19, 2022
@srebhan
Copy link
Contributor

srebhan commented Jul 20, 2022

FYI: PR for the integration test can be found in #11529.

@gkorland you might also want to change the link in your documentation to the official Telegraf, not that this PR is in... ;-)

@gkorland gkorland deleted the redistimeseries-plugin branch August 17, 2022 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis new plugin ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants