Skip to content

Commit 5294ca6

Browse files
Ignore only Insights RPC
1 parent b0cfeff commit 5294ca6

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

proxy/pkg/zdmproxy/cqlparser.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const (
2323
forwardToAsyncOnly = forwardDecision("async") // for "synchronous" requests that should be sent to the async connector (handshake requests)
2424
)
2525

26+
const (
27+
insightsRpcName = "InsightsRpc"
28+
)
29+
2630
type interceptedQueryType string
2731

2832
const (
@@ -215,10 +219,12 @@ func getRequestInfoFromQueryInfo(
215219
} else if queryInfo.getStatementType() == statementTypeUse {
216220
sendAlsoToAsync = true
217221
} else if queryInfo.getStatementType() == statementTypeCall {
218-
// RPC client, typically used by "insights reporter" for DSE
219-
forwardDecision = forwardToNone
220-
trackMetrics = false
221-
sendAlsoToAsync = false
222+
if queryInfo.getCallRpcName() == insightsRpcName {
223+
// ignore Insights client calls
224+
forwardDecision = forwardToNone
225+
trackMetrics = false
226+
sendAlsoToAsync = false
227+
}
222228
} else {
223229
sendAlsoToAsync = false
224230
}

proxy/pkg/zdmproxy/cqlparser_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func TestInspectFrame(t *testing.T) {
9595
{"OpCodeQuery UNKNOWN", args{mockQueryFrame(t, "UNKNOWN"), []*term{}, primaryClusterOrigin, forwardSystemQueriesToOrigin, forwardAuthToOrigin}, NewGenericRequestInfo(forwardToBoth, false, true)},
9696
{"OpCodeQuery CALL InsightsRpc.reportInsight(?)", args{mockQueryFrame(t, "CALL InsightsRpc.reportInsight(?)"), []*term{}, primaryClusterOrigin, forwardSystemQueriesToOrigin, forwardAuthToOrigin}, NewGenericRequestInfo(forwardToNone, false, false)},
9797
{"OpCodeQuery CALL InsightsRpc.reportInsight('a', 1, -2.3, true, '2020-01-01')", args{mockQueryFrame(t, "CALL InsightsRpc.reportInsight('a', 1, -2.3, true, '2020-01-01')"), []*term{}, primaryClusterOrigin, forwardSystemQueriesToOrigin, forwardAuthToOrigin}, NewGenericRequestInfo(forwardToNone, false, false)},
98+
{"OpCodeQuery CALL DseGraphRpc.getSchemaBlob(?)", args{mockQueryFrame(t, "CALL DseGraphRpc.getSchemaBlob(?)"), []*term{}, primaryClusterOrigin, forwardSystemQueriesToOrigin, forwardAuthToOrigin}, NewGenericRequestInfo(forwardToBoth, false, true)},
9899

99100
// PREPARE
100101
{"OpCodePrepare SELECT", args{mockPrepareFrame(t, "SELECT blah FROM ks1.t1"), []*term{}, primaryClusterOrigin, forwardSystemQueriesToOrigin, forwardAuthToOrigin}, NewPrepareRequestInfo(NewGenericRequestInfo(forwardToOrigin, true, true), []*term{}, false, "SELECT blah FROM ks1.t1", "")},

proxy/pkg/zdmproxy/queryinspector.go

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type QueryInfo interface {
5252
getStatementType() statementType
5353
getKeyspaceName() string
5454
getTableName() string
55+
getCallRpcName() string
5556

5657
// Returns the "current" keyspace when this request was parsed. This could have been set by a "USE" request beforehand
5758
// or by using the keyspace query/prepare flag in v5 or DseV2.
@@ -327,6 +328,7 @@ type cqlListener struct {
327328
timeUuidGenerator TimeUuidGenerator
328329

329330
requestKeyspace string
331+
callRpcName string
330332
}
331333

332334
func (l *cqlListener) getQuery() string {
@@ -345,6 +347,10 @@ func (l *cqlListener) getTableName() string {
345347
return l.tableName
346348
}
347349

350+
func (l *cqlListener) getCallRpcName() string {
351+
return l.callRpcName
352+
}
353+
348354
func (l *cqlListener) getRequestKeyspace() string {
349355
return l.requestKeyspace
350356
}
@@ -401,6 +407,19 @@ func (l *cqlListener) EnterCqlStatement(ctx *parser.CqlStatementContext) {
401407
}
402408
}
403409

410+
func (l *cqlListener) EnterCallStatement(ctx *parser.CallStatementContext) {
411+
if ctx.GetChildCount() < 2 {
412+
return
413+
}
414+
415+
// RPC name will be present as second child: CALL <rpc_name>.<rpc_method>(<params>)
416+
token := ctx.GetChild(1)
417+
switch token.(type) {
418+
case *parser.IdentifierContext:
419+
l.callRpcName = token.(*parser.IdentifierContext).GetText()
420+
}
421+
}
422+
404423
func (l *cqlListener) ExitSelectStatement(ctx *parser.SelectStatementContext) {
405424
if !isSystemKeyspace(l.getApplicableKeyspace()) {
406425
return

0 commit comments

Comments
 (0)