Class InMemoryStorage

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.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 )
     
    • Method Detail

      • acceptedSpanCount

        public int acceptedSpanCount()
      • clear

        public void clear()
      • getTraces

        public Call<java.util.List<java.util.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.

        Specified by:
        getTraces in interface SpanStore
      • getTraces

        public java.util.List<java.util.List<Span>> getTraces()
        Used for testing. Returns all traces unconditionally.
      • getDependencies

        public java.util.List<DependencyLink> getDependencies()
        Used for testing. Returns all dependency links unconditionally.
      • getTrace

        public Call<java.util.List<Span>> getTrace​(java.lang.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.

        Specified by:
        getTrace in interface SpanStore
        Specified by:
        getTrace in interface Traces
        Parameters:
        traceId - the trace ID
      • getTraces

        public Call<java.util.List<java.util.List<Span>>> getTraces​(java.lang.Iterable<java.lang.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.

        Specified by:
        getTraces in interface Traces
        Parameters:
        traceIds - a list of unique trace IDs.
        Returns:
        traces matching the supplied trace IDs, in any order
      • getDependencies

        public Call<java.util.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 interface SpanStore
        Parameters:
        endTs - only return links from spans where Span.timestamp() are at or before this time in epoch milliseconds.
        lookback - only return links from spans where Span.timestamp() are at or after (endTs - lookback) in milliseconds.
      • 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.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Component
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object