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

[jaeger-v2] Add support for Cassandra #5253

Merged
merged 14 commits into from
Mar 16, 2024

Conversation

Pushkarm029
Copy link
Member

Which problem is this PR solving?

Description of the changes

  • add support for cassandra

How was this change tested?

  • currently, tests are failing.

Checklist

@Pushkarm029
Copy link
Member Author

@james-ryans @akagami-harsh, please review.

Currently, TestCassandraStorageFactoryWithConfig is failing with a timeout error. Maybe some config issue???

@james-ryans
Copy link
Contributor

Currently, TestCassandraStorageFactoryWithConfig is failing with a timeout error. Maybe some config issue???

It is because you are trying to connect to HTTP server with Cassandra client, if you set the config with ConnectTimeout to 1 * time.Second you will get the connection timeout error

2024/03/06 23:25:39 gocql: unable to dial control conn 127.0.0.1:50134: gocql: no response to connection startup within timeout

That is because Cassandra connection is over TCP instead of HTTP. Perhaps, you should try to spawn a TCP server instead of HTTP server, here I found a guide to create one but I haven't successfully implement it for Cassandra connection. https://okanexe.medium.com/the-complete-guide-to-tcp-ip-connections-in-golang-1216dae27b5a

Signed-off-by: Pushkar Mishra <[email protected]>
@Pushkarm029
Copy link
Member Author

Pushkarm029 commented Mar 7, 2024

@yurishkuro, I cannot create a connection between the test and Cassandra. Everytime, i try something, I get this error :

Received unexpected error: gocql: unable to create session: unable to discover protocol version

Do you have any idea how I can do it?

In other tests, the first factory is created with f.NewFactory(), the mock session is passed in, and then it checks noError in f.initialize. But, here, we can't do the same. since both f.NewFactory() and f.Initialize() is part of the same function NewFactoryWithConfig().

f := NewFactory()
f.primaryConfig = newMockSessionBuilder(session, nil)
require.NoError(t, f.Initialize(metrics.NullFactory, logger))

edit : Adding on slack also, to get more ideas or suggestions.

@yurishkuro
Copy link
Member

now do we do that in Elastic? It also uses NewFactoryWithConfig pattern.

@Pushkarm029
Copy link
Member Author

Pushkarm029 commented Mar 7, 2024

Yes, in ElasticSearch we use the same NewFactoryWithConfig pattern. But there, in the test, we created a mock HTTP server to test, but it is not working here. -> Timeout Error

var mockCassandraResponse = []byte(`
{
	"Version": "3.11.11"
}
`)

func TestCccFactoryWithConfig(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write(mockCassandraResponse)
	}))
	defer server.Close()
	serverURL := server.URL
	serverURL = serverURL[len("http://"):]
	link, portStr, err := net.SplitHostPort(serverURL)
	require.NoError(t, err)
	port, err := strconv.Atoi(portStr)
	require.NoError(t, err)

	cfg := cassandraCfg.Configuration{
		Servers:        []string{link},
		Keyspace:       "test",
		ConnectTimeout: time.Second * 5,
		Port:           port,
	}
	factory, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
	require.NoError(t, err)
	defer factory.Close()
}
                Error Trace:    /home/pushkar/jaeger/plugin/storage/cassandra/factory_test.go:235
                Error:          Received unexpected error:
                                gocql: unable to create session: unable to discover protocol version: gocql: no response received from cassandra within timeout period
                Test:           TestCccFactoryWithConfig
--- FAIL: TestCccFactoryWithConfig (5.02s)

@yurishkuro
Copy link
Member

Creating a custom server is a useful pattern. Can we do the same for Cassandra? It may be more difficult as I don't think it's using HTTP protocol.

@Pushkarm029
Copy link
Member Author

Pushkarm029 commented Mar 7, 2024

Yeah, we can create a custom server for Cassandra. Can you provide some hints/examples?

EDIT : https://github.com/jaegertracing/jaeger/pull/4971/files : this seems relevant

@yurishkuro
Copy link
Member

Well again, you can see the example in ES tests. But ES uses HTTP so it's much easier to mock. I don't know if Cassandra can use HTTP protocol. If it's only some bespoke binary protocol, than it's harder to mock (perhaps there are libraries out there for that, or perhaps gocql has a place were we can substitute the actual server communication).

There are some tricks we can do internally by not combining creation and connection in a single step.

@Pushkarm029
Copy link
Member Author

removing unit tests

Signed-off-by: Pushkar Mishra <[email protected]>
@Pushkarm029 Pushkarm029 marked this pull request as ready for review March 8, 2024 17:32
@Pushkarm029 Pushkarm029 requested a review from a team as a code owner March 8, 2024 17:32
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 95.05%. Comparing base (990c4e1) to head (562658a).

Files Patch % Lines
plugin/storage/cassandra/factory.go 33.33% 6 Missing ⚠️
pkg/cassandra/config/config.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5253      +/-   ##
==========================================
- Coverage   95.11%   95.05%   -0.07%     
==========================================
  Files         339      339              
  Lines       16511    16529      +18     
==========================================
+ Hits        15705    15712       +7     
- Misses        618      629      +11     
  Partials      188      188              
Flag Coverage Δ
cassandra-3.x 26.47% <0.00%> (-0.06%) ⬇️
cassandra-4.x 26.47% <0.00%> (-0.06%) ⬇️
elasticsearch-5.x 21.71% <0.00%> (-0.07%) ⬇️
elasticsearch-6.x 21.71% <0.00%> (-0.05%) ⬇️
elasticsearch-7.x 21.81% <0.00%> (-0.05%) ⬇️
elasticsearch-8.x 21.88% <0.00%> (-0.07%) ⬇️
grpc-badger 19.21% <0.00%> (-0.02%) ⬇️
kafka 14.63% <0.00%> (-0.03%) ⬇️
opensearch-1.x 21.81% <0.00%> (-0.05%) ⬇️
opensearch-2.x 21.81% <0.00%> (-0.03%) ⬇️
unittests 92.67% <50.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@james-ryans
Copy link
Contributor

Pushkar, I believe what Yuri meant previously was that we should only leave the unit test that needs to connect to Cassandra (which we can't mock) and keep all other unit tests you successfully created. What do you think?

@Pushkarm029
Copy link
Member Author

ok, we can do it @james-ryans. btw i created a weekly milestone doc, do check it out.

Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
plugin/storage/cassandra/factory.go Outdated Show resolved Hide resolved
plugin/storage/cassandra/factory.go Outdated Show resolved Hide resolved
@yurishkuro yurishkuro added v2 changelog:exprimental Change to an experimental part of the code labels Mar 8, 2024
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
@@ -29,21 +30,21 @@ import (

// Configuration describes the configuration properties needed to connect to a Cassandra cluster
type Configuration struct {
Servers []string `validate:"nonzero" mapstructure:"servers"`
Servers []string `validate:"nonzero" mapstructure:"servers" valid:"required,url"`
Copy link
Member

Choose a reason for hiding this comment

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

do we know what would be using the validate: tags? Maybe we should convert them to valid:?

Copy link
Member Author

Choose a reason for hiding this comment

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

go-playground/validator is using the validate: tags. Since we are using asaskevich/govalidator, we should change this to valid:.

plugin/storage/cassandra/factory.go Outdated Show resolved Hide resolved
@Pushkarm029
Copy link
Member Author

working on it

@yurishkuro yurishkuro merged commit 3912f00 into jaegertracing:main Mar 16, 2024
34 of 35 checks passed
@Pushkarm029 Pushkarm029 deleted the cassandra_backend_support branch March 16, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:exprimental Change to an experimental part of the code v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants