You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/04/07 11:11:47 UTC
[GitHub] [cassandra] adelapena commented on a diff in pull request #1543: CASSANDRA-17509
adelapena commented on code in PR #1543:
URL: https://github.com/apache/cassandra/pull/1543#discussion_r844983598
##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailGroupByTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GuardrailGroupByTest extends GuardrailTester
+{
+ private final String query = "SELECT * FROM system_schema.keyspaces GROUP BY keyspace_name";
Review Comment:
Nit: could be static
##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -129,6 +129,11 @@
state -> !CONFIG_PROVIDER.getOrCreate(state).getUserTimestampsEnabled(),
"User provided timestamps (USING TIMESTAMP)");
+ public static final DisableFlag groupByEnabled =
+ new DisableFlag("group_by",
+ state -> !CONFIG_PROVIDER.getOrCreate(state).getGroupByEnabled(),
Review Comment:
Makes sense to me, probably every future enabled/disabled guardrail is going to have that negation.
##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailGroupByTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GuardrailGroupByTest extends GuardrailTester
+{
+ private final String query = "SELECT * FROM system_schema.keyspaces GROUP BY keyspace_name";
+
+ private void setGuardrail(boolean enabled)
+ {
+ Guardrails.instance.setGroupByEnabled(enabled);
+ }
+
+ @Test
+ public void checkExplicitlyDisabled() throws Throwable
+ {
+ setGuardrail(false);
+ assertFails(query, "GROUP BY functionality");
+ }
+
+ @Test
+ public void checkEnabled() throws Throwable
+ {
+ setGuardrail(true);
+ try
+ {
+ assertValid(query);
+ }
+ catch (AssertionError ae)
+ {
+ // We expect the query to _warn_ (i.e. fail the assertValid check), but with a non-guardrails warning and
+ // not a failure. Rather than extending the GuardrailsTester framework to handle this case of "warns but not
+ // with a guardrail warning", we just confirm here we saw the acceptable warning we expect but the query was
+ // allowed to run.
+ Assert.assertTrue(ae.getMessage().contains("used without partition key"));
+ }
+ }
+}
Review Comment:
Nit: missing newline at the end of the file
##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailGroupByTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GuardrailGroupByTest extends GuardrailTester
+{
+ private final String query = "SELECT * FROM system_schema.keyspaces GROUP BY keyspace_name";
+
+ private void setGuardrail(boolean enabled)
+ {
+ Guardrails.instance.setGroupByEnabled(enabled);
+ }
+
+ @Test
+ public void checkExplicitlyDisabled() throws Throwable
+ {
+ setGuardrail(false);
+ assertFails(query, "GROUP BY functionality");
+ }
+
+ @Test
+ public void checkEnabled() throws Throwable
Review Comment:
We could add a test to verify that internal queries and superusers are not affected by the guardrail. If `GuardrailGroupByTest.query` doesn't throw additional warnings it could be:
```java
@Test
public void testExcludedUsers() throws Throwable
{
setGuardrail(false);
testExcludedUsers(() -> query);
}
```
Otherwise it would be:
```java
@Test
public void testExcludedUsers() throws Throwable
{
setGuardrail(false);
testExcludedUsers(() -> String.format("SELECT * FROM %s.%s WHERE keyspace_name='%s' GROUP BY table_name",
SchemaConstants.SCHEMA_KEYSPACE_NAME,
SchemaKeyspaceTables.TABLES,
KEYSPACE));
}
```
##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailGroupByTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GuardrailGroupByTest extends GuardrailTester
+{
+ private final String query = "SELECT * FROM system_schema.keyspaces GROUP BY keyspace_name";
+
+ private void setGuardrail(boolean enabled)
+ {
+ Guardrails.instance.setGroupByEnabled(enabled);
+ }
+
+ @Test
+ public void checkExplicitlyDisabled() throws Throwable
+ {
+ setGuardrail(false);
+ assertFails(query, "GROUP BY functionality");
+ }
+
+ @Test
+ public void checkEnabled() throws Throwable
+ {
+ setGuardrail(true);
+ try
+ {
+ assertValid(query);
+ }
+ catch (AssertionError ae)
+ {
+ // We expect the query to _warn_ (i.e. fail the assertValid check), but with a non-guardrails warning and
+ // not a failure. Rather than extending the GuardrailsTester framework to handle this case of "warns but not
+ // with a guardrail warning", we just confirm here we saw the acceptable warning we expect but the query was
+ // allowed to run.
+ Assert.assertTrue(ae.getMessage().contains("used without partition key"));
Review Comment:
Maybe it would be easier to just use a query that doesn't throw a warning like, for example:
```java
private static final String query = String.format("SELECT * FROM %s.%s WHERE keyspace_name='%s' GROUP BY table_name",
SchemaConstants.SCHEMA_KEYSPACE_NAME,
SchemaKeyspaceTables.TABLES,
KEYSPACE);
```
Alternatively, modifying `GuardrailTester#assertValid` to accept non-guardrail warnings should be easy and has potential for reutilization on other tests, for example [this way](https://github.com/adelapena/cassandra/commit/de425dc1ad994aa01eb0f15a4670bbd376fa7b22).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org