Class InMemoryStorage
- java.lang.Object
-
- zipkin2.Component
-
- zipkin2.storage.StorageComponent
-
- zipkin2.storage.InMemoryStorage
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,AutocompleteTags
,ServiceAndSpanNames
,SpanConsumer
,SpanStore
,Traces
public final class InMemoryStorage extends StorageComponent implements SpanStore, SpanConsumer, AutocompleteTags, ServiceAndSpanNames, Traces
Test storage component that keeps all spans in memory, accepting them on the calling thread.Internally, spans are indexed on 64-bit trace ID
Here's an example of some traces in memory:
spansByTraceIdTimeStamp: <aaaa,July 4> --> ( spanA(time:July 4, traceId:aaaa, service:foo, name:GET), spanB(time:July 4, traceId:aaaa, service:bar, name:GET) ) <cccc,July 4> --> ( spanC(time:July 4, traceId:aaaa, service:foo, name:GET) ) <bbbb,July 5> --> ( spanD(time:July 5, traceId:bbbb, service:biz, name:GET) ) <bbbb,July 6> --> ( spanE(time:July 6, traceId:bbbb) service:foo, name:POST ) traceIdToTraceIdTimeStamps: aaaa --> [ <aaaa,July 4> ] bbbb --> [ <bbbb,July 5>, <bbbb,July 6> ] cccc --> [ <cccc,July 4> ] serviceToTraceIds: foo --> [ <aaaa>, <cccc>, <bbbb> ] bar --> [ <aaaa> ] biz --> [ <bbbb> ] serviceToSpanNames: bar --> ( GET ) biz --> ( GET ) foo --> ( GET, POST )
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InMemoryStorage.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Call<Void>
accept(List<Span> spans)
int
acceptedSpanCount()
InMemoryStorage
autocompleteTags()
void
clear()
void
close()
Closes any network resources created implicitly by the component.List<DependencyLink>
getDependencies()
Used for testing.Call<List<DependencyLink>>
getDependencies(long endTs, long lookback)
Returns dependency links derived from spans in an interval contained by (endTs - lookback) or empty if none are found.Call<List<String>>
getKeys()
Retrieves the list of tag getKeys whose values may be returned byAutocompleteTags.getValues(String)
.Call<List<String>>
getRemoteServiceNames(String service)
Call<List<String>>
getServiceNames()
Call<List<String>>
getSpanNames(String service)
Retrieves allspan names
recorded by aservice
, sorted lexicographically.Call<List<Span>>
getTrace(String traceId)
Retrieves spans that share a 128-bit trace id with no ordering expectation or empty if none are found.List<List<Span>>
getTraces()
Used for testing.Call<List<List<Span>>>
getTraces(Iterable<String> traceIds)
Retrieves any traces with the specified IDs.Call<List<List<Span>>>
getTraces(QueryRequest request)
Retrieves spans grouped by trace ID from the storage system with no ordering expectation.Call<List<String>>
getValues(String key)
Retrieves the list of values, if the input is configured for autocompletion.static InMemoryStorage.Builder
newBuilder()
InMemoryStorage
serviceAndSpanNames()
SpanConsumer
spanConsumer()
InMemoryStorage
spanStore()
String
toString()
InMemoryStorage
traces()
-
Methods inherited from class zipkin2.storage.StorageComponent
isOverCapacity
-
-
-
-
Method Detail
-
newBuilder
public static InMemoryStorage.Builder newBuilder()
-
acceptedSpanCount
public int acceptedSpanCount()
-
clear
public void clear()
-
getTraces
public Call<List<List<Span>>> getTraces(QueryRequest request)
Description copied from interface:SpanStore
Retrieves spans grouped by trace ID from the storage system with no ordering expectation.When strict trace ID is disabled, spans are grouped by the right-most 16 characters of the trace ID.
-
getDependencies
public List<DependencyLink> getDependencies()
Used for testing. Returns all dependency links unconditionally.
-
getTrace
public Call<List<Span>> getTrace(String traceId)
Description copied from interface:SpanStore
Retrieves spans that share a 128-bit trace id with no ordering expectation or empty if none are found.When strict trace ID is disabled, spans with the same right-most 16 characters are returned even if the characters to the left are not.
Implementations should use
Span.normalizeTraceId(String)
to ensure consistency.
-
getTraces
public Call<List<List<Span>>> getTraces(Iterable<String> traceIds)
Description copied from interface:Traces
Retrieves any traces with the specified IDs. Results return in any order, and can be empty.When strict trace ID is disabled, spans with the same right-most 16 characters are returned even if the characters to the left are not.
Implementations should use
Span.normalizeTraceId(String)
on each input trace ID to ensure consistency.
-
getServiceNames
public Call<List<String>> getServiceNames()
Description copied from interface:SpanStore
- Specified by:
getServiceNames
in interfaceServiceAndSpanNames
- Specified by:
getServiceNames
in interfaceSpanStore
-
getRemoteServiceNames
public Call<List<String>> getRemoteServiceNames(String service)
Description copied from interface:ServiceAndSpanNames
- Specified by:
getRemoteServiceNames
in interfaceServiceAndSpanNames
-
getSpanNames
public Call<List<String>> getSpanNames(String service)
Description copied from interface:SpanStore
Retrieves allspan names
recorded by aservice
, sorted lexicographically.- Specified by:
getSpanNames
in interfaceServiceAndSpanNames
- Specified by:
getSpanNames
in interfaceSpanStore
-
getDependencies
public Call<List<DependencyLink>> getDependencies(long endTs, long lookback)
Description copied from interface:SpanStore
Returns dependency links derived from spans in an interval contained by (endTs - lookback) or empty if none are found.Implementations may bucket aggregated data, for example daily. When this is the case, endTs may be floored to align with that bucket, for example midnight if daily. lookback applies to the original endTs, even when bucketed. Using the daily example, if endTs was 11pm and lookback was 25 hours, the implementation would query against 2 buckets.
Some implementations parse spans from storage and call
DependencyLinker
to aggregate links. The reason is certain graph logic, such as skipping up the tree is difficult to implement as a storage query.Spans are grouped by the right-most 16 characters of the trace ID. This ensures call counts are not incremented twice due to one hop downgrading from 128 to 64-bit trace IDs.
- Specified by:
getDependencies
in interfaceSpanStore
- Parameters:
endTs
- only return links from spans whereSpan.timestamp()
are at or before this time in epoch milliseconds.lookback
- only return links from spans whereSpan.timestamp()
are at or after (endTs - lookback) in milliseconds.
-
getKeys
public Call<List<String>> getKeys()
Description copied from interface:AutocompleteTags
Retrieves the list of tag getKeys whose values may be returned byAutocompleteTags.getValues(String)
.- Specified by:
getKeys
in interfaceAutocompleteTags
- See Also:
StorageComponent.Builder.autocompleteKeys(List)
-
getValues
public Call<List<String>> getValues(String key)
Description copied from interface:AutocompleteTags
Retrieves the list of values, if the input is configured for autocompletion. If a key is not configured, or there are no values available, an empty result will be returned.- Specified by:
getValues
in interfaceAutocompleteTags
- See Also:
StorageComponent.Builder.autocompleteKeys(List)
-
traces
public InMemoryStorage traces()
- Overrides:
traces
in classStorageComponent
-
spanStore
public InMemoryStorage spanStore()
- Specified by:
spanStore
in classStorageComponent
-
autocompleteTags
public InMemoryStorage autocompleteTags()
- Overrides:
autocompleteTags
in classStorageComponent
-
serviceAndSpanNames
public InMemoryStorage serviceAndSpanNames()
- Overrides:
serviceAndSpanNames
in classStorageComponent
-
spanConsumer
public SpanConsumer spanConsumer()
- Specified by:
spanConsumer
in classStorageComponent
-
close
public void close()
Description copied from class:Component
Closes any network resources created implicitly by the component.For example, if this created a connection, it would close it. If it was provided one, this would close any sessions, but leave the connection open.
-
-