-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Cassandra support for Autocomplete tags
- Loading branch information
Showing
39 changed files
with
855 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ge/cassandra-v1/src/main/java/zipkin2/storage/cassandra/v1/CassandraAutocompleteTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2015-2018 The OpenZipkin Authors | ||
* | ||
* Licensed 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 zipkin2.storage.cassandra.v1; | ||
|
||
import java.util.List; | ||
import zipkin2.Call; | ||
import zipkin2.storage.AutocompleteTags; | ||
|
||
final class CassandraAutocompleteTags implements AutocompleteTags { | ||
final boolean enabled; | ||
final Call<List<String>> keysCall; | ||
final SelectAutocompleteValues.Factory valuesCallFactory; | ||
|
||
CassandraAutocompleteTags(CassandraStorage storage) { | ||
enabled = storage.searchEnabled && !storage.autocompleteKeys.isEmpty(); | ||
keysCall = Call.create(storage.autocompleteKeys); | ||
valuesCallFactory = enabled ? new SelectAutocompleteValues.Factory(storage.session()) : null; | ||
} | ||
|
||
@Override public Call<List<String>> getKeys() { | ||
if (!enabled) return Call.emptyList(); | ||
return keysCall.clone(); | ||
} | ||
|
||
@Override public Call<List<String>> getValues(String key) { | ||
if (key == null) throw new NullPointerException("key == null"); | ||
if (key.isEmpty()) throw new IllegalArgumentException("key was empty"); | ||
if (!enabled) return Call.emptyList(); | ||
return valuesCallFactory.create(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...rage/cassandra-v1/src/main/java/zipkin2/storage/cassandra/v1/InsertAutocompleteValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2015-2018 The OpenZipkin Authors | ||
* | ||
* Licensed 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 zipkin2.storage.cassandra.v1; | ||
|
||
import com.datastax.driver.core.PreparedStatement; | ||
import com.datastax.driver.core.ResultSet; | ||
import com.datastax.driver.core.ResultSetFuture; | ||
import com.datastax.driver.core.Session; | ||
import com.datastax.driver.core.querybuilder.Insert; | ||
import com.datastax.driver.core.querybuilder.QueryBuilder; | ||
import java.util.Map; | ||
import zipkin2.Call; | ||
import zipkin2.storage.cassandra.internal.call.DeduplicatingCall; | ||
|
||
import static zipkin2.storage.cassandra.v1.Tables.TABLE_AUTOCOMPLETE_TAGS; | ||
|
||
final class InsertAutocompleteValue extends DeduplicatingCall<Map.Entry<String, String>> { | ||
|
||
static class Factory | ||
extends DeduplicatingCall.Factory<Map.Entry<String, String>, InsertAutocompleteValue> { | ||
final Session session; | ||
final PreparedStatement preparedStatement; | ||
|
||
/** | ||
* @param indexTtl how long cassandra will persist the rows | ||
* @param redundantCallTtl how long in milliseconds to obviate redundant calls | ||
*/ | ||
Factory(Session session, int indexTtl, int redundantCallTtl) { | ||
super(redundantCallTtl); | ||
this.session = session; | ||
Insert insertQuery = QueryBuilder.insertInto(TABLE_AUTOCOMPLETE_TAGS) | ||
.value("key", QueryBuilder.bindMarker("key")) | ||
.value("value", QueryBuilder.bindMarker("value")); | ||
if (indexTtl > 0) insertQuery.using(QueryBuilder.ttl(indexTtl)); | ||
this.preparedStatement = session.prepare(insertQuery); | ||
} | ||
|
||
@Override protected InsertAutocompleteValue newCall(Map.Entry<String, String> input) { | ||
return new InsertAutocompleteValue(this, input); | ||
} | ||
} | ||
|
||
final Factory factory; | ||
final Map.Entry<String, String> input; | ||
|
||
InsertAutocompleteValue(Factory factory, Map.Entry<String, String> input) { | ||
super(factory, input); | ||
this.factory = factory; | ||
this.input = input; | ||
} | ||
|
||
@Override protected ResultSetFuture newFuture() { | ||
return factory.session.executeAsync(factory.preparedStatement.bind() | ||
.setString("key", input.getKey()) | ||
.setString("value", input.getValue())); | ||
} | ||
|
||
@Override public String toString() { | ||
return "InsertAutocompleteValue(" + input + ")"; | ||
} | ||
|
||
@Override public Call<ResultSet> clone() { | ||
return new InsertAutocompleteValue(factory, input); | ||
} | ||
} |
Oops, something went wrong.