Ejemplo n.º 1
0
        public void TraceData()
        {
            List <Input> inputs = new List <Input>();

            int startLineNumber;
            int endLineNumber;

            //----------------------------------------------------------------
            //  Point Operation Statistics
            //----------------------------------------------------------------
            {
                {
                    startLineNumber = GetLineNumber();
                    TraceForBaselineTesting rootTrace;
                    using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                    {
                        PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum(
                            activityId: Guid.Empty.ToString(),
                            responseTimeUtc: new DateTime(2020, 1, 2, 3, 4, 5, 6),
                            statusCode: System.Net.HttpStatusCode.OK,
                            subStatusCode: Documents.SubStatusCodes.WriteForbidden,
                            requestCharge: 4,
                            errorMessage: null,
                            method: HttpMethod.Post,
                            requestUri: "http://localhost.com",
                            requestSessionToken: nameof(PointOperationStatisticsTraceDatum.RequestSessionToken),
                            responseSessionToken: nameof(PointOperationStatisticsTraceDatum.ResponseSessionToken),
                            beLatencyInMs: "0.42");
                        rootTrace.AddDatum("Point Operation Statistics", datum);
                    }
                    endLineNumber = GetLineNumber();

                    inputs.Add(new Input("Point Operation Statistics", rootTrace, startLineNumber, endLineNumber));
                }

                {
                    startLineNumber = GetLineNumber();
                    TraceForBaselineTesting rootTrace;
                    using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                    {
                        PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum(
                            activityId: default,
        public void Serialization()
        {
            List <Input> inputs = new List <Input>();

            int startLineNumber;
            int endLineNumber;

            //----------------------------------------------------------------
            //  Root Trace
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Root Trace With Datum
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTraceWithDatum;
                using (rootTraceWithDatum = TraceForBaselineTesting.GetRootTrace())
                {
                    rootTraceWithDatum.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics));
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace With Datum", rootTraceWithDatum, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Root Trace With One Child
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    using (ITrace childTrace1 = rootTrace.StartChild("Child1"))
                    {
                    }
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace With One Child", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Root Trace With One Child With Datum
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    using (ITrace childTrace1 = rootTrace.StartChild("Child1"))
                    {
                        childTrace1.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics));
                    }
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace With One Child With Datum", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Root Trace With Two Children
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    using (ITrace childTrace1 = rootTrace.StartChild("Child1"))
                    {
                    }

                    using (ITrace childTrace2 = rootTrace.StartChild("Child2"))
                    {
                    }
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace With Two Children", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Root Trace With Two Children With Info
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    using (ITrace childTrace1 = rootTrace.StartChild("Child1"))
                    {
                        childTrace1.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics));
                    }

                    using (ITrace childTrace2 = rootTrace.StartChild("Child2"))
                    {
                        childTrace2.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics));
                    }
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Root Trace With Two Children With Info", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Trace With Grandchidren
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    using (ITrace childTrace1 = rootTrace.StartChild(
                               name: "Child1",
                               component: TraceComponent.Unknown,
                               level: TraceLevel.Info))
                    {
                        using (ITrace child1Child1 = childTrace1.StartChild(
                                   name: "Child1Child1",
                                   component: TraceComponent.Unknown,
                                   level: TraceLevel.Info))
                        {
                        }

                        using (ITrace child1Child2 = childTrace1.StartChild(
                                   name: "Child1Child2",
                                   component: TraceComponent.Unknown,
                                   level: TraceLevel.Info))
                        {
                        }
                    }

                    using (ITrace childTrace2 = rootTrace.StartChild(
                               name: "Child2",
                               component: TraceComponent.Unknown,
                               level: TraceLevel.Info))
                    {
                        using (ITrace child2Child1 = childTrace2.StartChild(
                                   name: "Child2Child1",
                                   component: TraceComponent.Unknown,
                                   level: TraceLevel.Info))
                        {
                        }

                        using (ITrace child2Child2 = childTrace2.StartChild(
                                   name: "Child2Child2",
                                   component: TraceComponent.Unknown,
                                   level: TraceLevel.Info))
                        {
                        }

                        using (ITrace child2Child3 = childTrace2.StartChild(
                                   name: "Child2Child3",
                                   component: TraceComponent.Unknown,
                                   level: TraceLevel.Info))
                        {
                        }
                    }
                }

                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Trace With Grandchildren", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            this.ExecuteTestSuite(inputs);
        }
        public async Task ScenariosAsync()
        {
            List <Input> inputs = new List <Input>();

            int startLineNumber;
            int endLineNumber;

            //----------------------------------------------------------------
            //  ReadFeed
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                int numItems = 100;
                IDocumentContainer documentContainer = await CreateDocumentContainerAsync(numItems);

                CrossPartitionReadFeedAsyncEnumerator enumerator = CrossPartitionReadFeedAsyncEnumerator.Create(
                    documentContainer,
                    new CrossFeedRangeState <ReadFeedState>(ReadFeedCrossFeedRangeState.CreateFromBeginning().FeedRangeStates),
                    new ReadFeedPaginationOptions(pageSizeHint: 10),
                    cancellationToken: default);

                int numChildren = 1; // One extra since we need to read one past the last user page to get the null continuation.
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    while (await enumerator.MoveNextAsync(rootTrace))
                    {
                        numChildren++;
                    }
                }

                Assert.AreEqual(numChildren, rootTrace.Children.Count);
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("ReadFeed", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  ChangeFeed
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                int numItems = 100;
                IDocumentContainer documentContainer = await CreateDocumentContainerAsync(numItems);

                CrossPartitionChangeFeedAsyncEnumerator enumerator = CrossPartitionChangeFeedAsyncEnumerator.Create(
                    documentContainer,
                    new CrossFeedRangeState <ChangeFeedState>(
                        ChangeFeedCrossFeedRangeState.CreateFromBeginning().FeedRangeStates),
                    new ChangeFeedPaginationOptions(
                        ChangeFeedMode.Incremental,
                        pageSizeHint: int.MaxValue),
                    cancellationToken: default);

                int numChildren = 0;
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    while (await enumerator.MoveNextAsync(rootTrace))
                    {
                        numChildren++;

                        if (enumerator.Current.Result.Page is ChangeFeedNotModifiedPage)
                        {
                            break;
                        }
                    }
                }

                Assert.AreEqual(numChildren, rootTrace.Children.Count);
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("ChangeFeed", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Query
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                int numItems = 100;
                IDocumentContainer documentContainer = await CreateDocumentContainerAsync(numItems);

                IQueryPipelineStage pipelineStage = CreatePipeline(documentContainer, "SELECT * FROM c", pageSize: 10);

                TraceForBaselineTesting rootTrace;
                int numChildren = 1; // One extra since we need to read one past the last user page to get the null continuation.
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    while (await pipelineStage.MoveNextAsync(rootTrace))
                    {
                        numChildren++;
                    }
                }

                Assert.AreEqual(numChildren, rootTrace.Children.Count);
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Query", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            this.ExecuteTestSuite(inputs);
        }
        public void TraceData()
        {
            List <Input> inputs = new List <Input>();

            int startLineNumber;
            int endLineNumber;

            //----------------------------------------------------------------
            //  Point Operation Statistics
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    PointOperationStatisticsTraceDatum datum = new PointOperationStatisticsTraceDatum(
                        activityId: Guid.Empty.ToString(),
                        responseTimeUtc: new DateTime(2020, 1, 2, 3, 4, 5, 6),
                        statusCode: System.Net.HttpStatusCode.OK,
                        subStatusCode: Documents.SubStatusCodes.WriteForbidden,
                        requestCharge: 4,
                        errorMessage: null,
                        method: HttpMethod.Post,
                        requestUri: "http://localhost.com",
                        requestSessionToken: nameof(PointOperationStatisticsTraceDatum.RequestSessionToken),
                        responseSessionToken: nameof(PointOperationStatisticsTraceDatum.ResponseSessionToken));
                    rootTrace.AddDatum("Point Operation Statistics", datum);
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Point Operation Statistics", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Query Metrics
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum(
                        new QueryMetrics(
                            BackendMetricsTests.MockBackendMetrics,
                            IndexUtilizationInfoTests.MockIndexUtilizationInfo,
                            ClientSideMetricsTests.MockClientSideMetrics));
                    rootTrace.AddDatum("Query Metrics", datum);
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Query Metrics", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  Client Side Request Stats
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    ClientSideRequestStatisticsTraceDatum datum = new ClientSideRequestStatisticsTraceDatum(DateTime.MinValue);

                    Uri uri1 = new Uri("http://someUri1.com");
                    Uri uri2 = new Uri("http://someUri2.com");

                    datum.ContactedReplicas.Add(uri1);
                    datum.ContactedReplicas.Add(uri2);

                    ClientSideRequestStatisticsTraceDatum.AddressResolutionStatistics mockStatistics = new ClientSideRequestStatisticsTraceDatum.AddressResolutionStatistics(
                        DateTime.MinValue,
                        DateTime.MaxValue,
                        "http://localhost.com");
                    datum.EndpointToAddressResolutionStatistics["asdf"]  = mockStatistics;
                    datum.EndpointToAddressResolutionStatistics["asdf2"] = mockStatistics;

                    datum.FailedReplicas.Add(uri1);
                    datum.FailedReplicas.Add(uri2);

                    datum.RegionsContacted.Add(uri1);
                    datum.RegionsContacted.Add(uri2);

                    datum.RequestEndTimeUtc = DateTime.MaxValue;

                    StoreResponseStatistics storeResponseStatistics = new StoreResponseStatistics(
                        DateTime.MinValue,
                        DateTime.MaxValue,
                        new Documents.StoreResult(
                            storeResponse: new StoreResponse(),
                            exception: null,
                            partitionKeyRangeId: 42.ToString(),
                            lsn: 1337,
                            quorumAckedLsn: 23,
                            requestCharge: 3.14,
                            currentReplicaSetSize: 4,
                            currentWriteQuorum: 3,
                            isValid: true,
                            storePhysicalAddress: new Uri("http://storephysicaladdress.com"),
                            globalCommittedLSN: 1234,
                            numberOfReadRegions: 13,
                            itemLSN: 15,
                            sessionToken: new SimpleSessionToken(42),
                            usingLocalLSN: true,
                            activityId: Guid.Empty.ToString()),
                        ResourceType.Document,
                        OperationType.Query,
                        uri1);
                    datum.StoreResponseStatisticsList.Add(storeResponseStatistics);
                    rootTrace.AddDatum("Client Side Request Stats", datum);
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("Client Side Request Stats", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            //----------------------------------------------------------------
            //  CPU History
            //----------------------------------------------------------------
            {
                startLineNumber = GetLineNumber();
                TraceForBaselineTesting rootTrace;
                using (rootTrace = TraceForBaselineTesting.GetRootTrace())
                {
                    CpuHistoryTraceDatum datum = new CpuHistoryTraceDatum(
                        new Documents.Rntbd.CpuLoadHistory(
                            new ReadOnlyCollection <Documents.Rntbd.CpuLoad>(
                                new List <Documents.Rntbd.CpuLoad>()
                    {
                        new Documents.Rntbd.CpuLoad(DateTime.MinValue, 42),
                        new Documents.Rntbd.CpuLoad(DateTime.MinValue, 23),
                    }),
                            monitoringInterval: TimeSpan.MaxValue));
                    rootTrace.AddDatum("CPU History", datum);
                }
                endLineNumber = GetLineNumber();

                inputs.Add(new Input("CPU History", rootTrace, startLineNumber, endLineNumber));
            }
            //----------------------------------------------------------------

            this.ExecuteTestSuite(inputs);
        }