-
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.
Merge pull request #107 from anuraaga/elasticsearch
Add an elasticsearch span store.
- Loading branch information
Showing
30 changed files
with
1,270 additions
and
23 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
56 changes: 56 additions & 0 deletions
56
interop/src/test/java/zipkin/elasticsearch/ElasticsearchScalaDependencyStoreTest.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,56 @@ | ||
/** | ||
* Copyright 2015-2016 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 zipkin.elasticsearch; | ||
|
||
import com.twitter.zipkin.common.Span; | ||
import com.twitter.zipkin.storage.DependencyStore; | ||
import com.twitter.zipkin.storage.DependencyStoreSpec; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.BeforeClass; | ||
import scala.collection.immutable.List; | ||
import zipkin.DependencyLink; | ||
import zipkin.InMemorySpanStore; | ||
import zipkin.SpanStore; | ||
import zipkin.interop.ScalaDependencyStoreAdapter; | ||
import zipkin.interop.ScalaSpanStoreAdapter; | ||
|
||
import static zipkin.internal.Util.midnightUTC; | ||
|
||
public class ElasticsearchScalaDependencyStoreTest extends DependencyStoreSpec { | ||
private static ElasticsearchSpanStore spanStore; | ||
|
||
@BeforeClass | ||
public static void setupDB() { | ||
spanStore = ElasticsearchTestGraph.INSTANCE.spanStore(); | ||
} | ||
|
||
public DependencyStore store() { | ||
return new ScalaDependencyStoreAdapter(spanStore); | ||
} | ||
|
||
@Override | ||
public void processDependencies(List<Span> input) { | ||
SpanStore mem = new InMemorySpanStore(); | ||
new ScalaSpanStoreAdapter(mem).apply(input); | ||
java.util.List<DependencyLink> | ||
links = mem.getDependencies(today() + TimeUnit.DAYS.toMillis(1), null); | ||
|
||
long midnight = midnightUTC(((long) input.apply(0).timestamp().get()) / 1000); | ||
ElasticsearchTestGraph.INSTANCE.spanStore().writeDependencyLinks(links, midnight); | ||
} | ||
|
||
public void clear() { | ||
spanStore.clear(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
interop/src/test/java/zipkin/elasticsearch/ElasticsearchScalaSpanStoreTest.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,36 @@ | ||
/** | ||
* Copyright 2015-2016 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 zipkin.elasticsearch; | ||
|
||
import com.twitter.zipkin.storage.SpanStore; | ||
import com.twitter.zipkin.storage.SpanStoreSpec; | ||
import org.junit.BeforeClass; | ||
import zipkin.interop.ScalaSpanStoreAdapter; | ||
|
||
public class ElasticsearchScalaSpanStoreTest extends SpanStoreSpec { | ||
private static ElasticsearchSpanStore spanStore; | ||
|
||
@BeforeClass | ||
public static void setupDB() { | ||
spanStore = ElasticsearchTestGraph.INSTANCE.spanStore(); | ||
} | ||
|
||
public SpanStore store() { | ||
return new ScalaSpanStoreAdapter(spanStore); | ||
} | ||
|
||
public void clear() { | ||
spanStore.clear(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
interop/src/test/java/zipkin/elasticsearch/ElasticsearchTestGraph.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,44 @@ | ||
/** | ||
* Copyright 2015-2016 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 zipkin.elasticsearch; | ||
|
||
import org.elasticsearch.client.transport.NoNodeAvailableException; | ||
import org.junit.AssumptionViolatedException; | ||
|
||
enum ElasticsearchTestGraph { | ||
INSTANCE; | ||
|
||
static final ElasticsearchConfig CONFIG = new ElasticsearchConfig.Builder().build(); | ||
|
||
static { | ||
// Avoid race-conditions in travis by forcing read-your-writes consistency. | ||
ElasticsearchSpanConsumer.BLOCK_ON_FUTURES = true; | ||
} | ||
|
||
private AssumptionViolatedException ex; | ||
private ElasticsearchSpanStore spanStore; | ||
|
||
/** A lot of tech debt here because the spanstore constructor performs I/O. */ | ||
synchronized ElasticsearchSpanStore spanStore() { | ||
if (ex != null) throw ex; | ||
if (this.spanStore == null) { | ||
try { | ||
this.spanStore = new ElasticsearchSpanStore(CONFIG); | ||
} catch (NoNodeAvailableException e) { | ||
throw ex = new AssumptionViolatedException(e.getMessage()); | ||
} | ||
} | ||
return spanStore; | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
zipkin-server/src/main/java/zipkin/server/ZipkinElasticsearchProperties.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,64 @@ | ||
/** | ||
* Copyright 2015-2016 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 zipkin.server; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("elasticsearch") | ||
public class ZipkinElasticsearchProperties { | ||
|
||
/** | ||
* The elasticsearch cluster to connect to, defaults to "elasticsearch". | ||
*/ | ||
private String cluster = "elasticsearch"; | ||
|
||
/** | ||
* A comma separated list of elasticsearch hostnodes to connect to, in host:port | ||
* format. The port should be the transport port, not the http port. Defaults to | ||
* "localhost:9300". | ||
*/ | ||
private String hosts = "localhost:9300"; | ||
|
||
/** | ||
* The index prefix to use when generating daily index names. Defaults to zipkin. | ||
*/ | ||
private String index = "zipkin"; | ||
|
||
public String getCluster() { | ||
return cluster; | ||
} | ||
|
||
public ZipkinElasticsearchProperties setCluster(String cluster) { | ||
this.cluster = cluster; | ||
return this; | ||
} | ||
|
||
public String getHosts() { | ||
return hosts; | ||
} | ||
|
||
public ZipkinElasticsearchProperties setHosts(String hosts) { | ||
this.hosts = hosts; | ||
return this; | ||
} | ||
|
||
public String getIndex() { | ||
return index; | ||
} | ||
|
||
public ZipkinElasticsearchProperties setIndex(String index) { | ||
this.index = index; | ||
return this; | ||
} | ||
} |
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
Oops, something went wrong.