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 classInMemoryStorage.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Call<Void>accept(List<Span> spans)intacceptedSpanCount()InMemoryStorageautocompleteTags()voidclear()voidclose()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 namesrecorded 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.BuildernewBuilder()InMemoryStorageserviceAndSpanNames()SpanConsumerspanConsumer()InMemoryStoragespanStore()StringtoString()InMemoryStoragetraces()-
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:SpanStoreRetrieves 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:SpanStoreRetrieves 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:TracesRetrieves 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:
getServiceNamesin interfaceServiceAndSpanNames- Specified by:
getServiceNamesin interfaceSpanStore
-
getRemoteServiceNames
public Call<List<String>> getRemoteServiceNames(String service)
Description copied from interface:ServiceAndSpanNames- Specified by:
getRemoteServiceNamesin interfaceServiceAndSpanNames
-
getSpanNames
public Call<List<String>> getSpanNames(String service)
Description copied from interface:SpanStoreRetrieves allspan namesrecorded by aservice, sorted lexicographically.- Specified by:
getSpanNamesin interfaceServiceAndSpanNames- Specified by:
getSpanNamesin interfaceSpanStore
-
getDependencies
public Call<List<DependencyLink>> getDependencies(long endTs, long lookback)
Description copied from interface:SpanStoreReturns 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
DependencyLinkerto 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:
getDependenciesin 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:AutocompleteTagsRetrieves the list of tag getKeys whose values may be returned byAutocompleteTags.getValues(String).- Specified by:
getKeysin interfaceAutocompleteTags- See Also:
StorageComponent.Builder.autocompleteKeys(List)
-
getValues
public Call<List<String>> getValues(String key)
Description copied from interface:AutocompleteTagsRetrieves 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:
getValuesin interfaceAutocompleteTags- See Also:
StorageComponent.Builder.autocompleteKeys(List)
-
traces
public InMemoryStorage traces()
- Overrides:
tracesin classStorageComponent
-
spanStore
public InMemoryStorage spanStore()
- Specified by:
spanStorein classStorageComponent
-
autocompleteTags
public InMemoryStorage autocompleteTags()
- Overrides:
autocompleteTagsin classStorageComponent
-
serviceAndSpanNames
public InMemoryStorage serviceAndSpanNames()
- Overrides:
serviceAndSpanNamesin classStorageComponent
-
spanConsumer
public SpanConsumer spanConsumer()
- Specified by:
spanConsumerin classStorageComponent
-
close
public void close()
Description copied from class:ComponentCloses 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.
-
-