Exemplo n.º 1
0
        public void ConstructingARayThroughACornerOfTheCanvas_ShouldWork()
        {
            var c = new Camera(201, 101, Math.PI / 2);
            var s = new DefaultSampler(c);
            var r = s.RayForPixel(0, 0);

            Assert.Equal(new Point(0, 0, 0), r.Origin, PointComparer);
            Assert.Equal(new Vector(0.66519, 0.33259, -0.66851), r.Direction, VectorComparer);
        }
 public void Close()
 {
     lock (_lock)
     {
         DefaultSampler.Close();
         foreach (var sampler in OperationNameToSampler.Values)
         {
             sampler.Close();
         }
     }
 }
Exemplo n.º 3
0
        public void ConstructingARayWhenTheCameraIsTransformed_ShouldWork()
        {
            var c = new Camera(201, 101, Math.PI / 2);

            c.Transform = Transformation.Rotation_y(Math.PI / 4) * Transformation.Translation(0, -2, 5);
            var s = new DefaultSampler(c);
            var r = s.RayForPixel(100, 50);

            Assert.Equal(new Point(0, 2, -5), r.Origin, PointComparer);
            Assert.Equal(new Vector(Math.Sqrt(2) / 2, 0, -Math.Sqrt(2) / 2), r.Direction, VectorComparer);
        }
 /// <summary>Closes the sampler, and any sub-samplers.</summary>
 public void Close()
 {
     lock (_lock)
     {
         DefaultSampler.Close();
         foreach (var sampler in SamplingFilters.Select(f => f.TargetSampler))
         {
             sampler.Close();
         }
     }
 }
        /// <summary>Makes a decision on tracing a span.</summary>
        /// <param name="operation">The operation being executed. (This is not just the HTTP Method)</param>
        /// <param name="id">The ID of the span.</param>
        public SamplingStatus Sample(string operation, TraceId id)
        {
            lock (_lock)
            {
                var context = HttpContextAccessor.HttpContext;

                return(SamplingFilters.Find(f => f.ShouldSample(context.Request))
                       ?.TargetSampler?.Sample(operation, id)
                       ?? DefaultSampler.Sample(operation, id));
            }
        }
Exemplo n.º 6
0
        public void TestCreateRayThroughCenterOfCanvas()
        {
            var          c        = new Camera(201, 101, Math.PI / 2);
            var          s        = new DefaultSampler(new World(), c);
            var          r        = s.RayForPixel(100, 50);
            const double epsilon  = 0.00001;
            var          comparer = Vector4.GetEqualityComparer(epsilon);

            Assert.Equal(Vector4.CreatePosition(0, 0, 0), r.Origin, comparer);
            Assert.Equal(Vector4.CreateDirection(0, 0, -1), r.Direction, comparer);
        }
Exemplo n.º 7
0
        public void SampleWorksAsExpected()
        {
            var sampler = new DefaultSampler(NoSalt, 0.000005f);

            const int shouldTraceId = 4;

            Assert.True(sampler.Sample(shouldTraceId));

            const int notTraceId = 5;

            Assert.False(sampler.Sample(notTraceId));
        }
Exemplo n.º 8
0
        public void TestCreateRayThroughCornerOfCanvas()
        {
            var          c = new Camera(201, 101, Math.PI / 2);
            var          s = new DefaultSampler(new World(), c);
            var          r = s.RayForPixel(0, 0);
            var          expectedOrigin    = Vector4.CreatePosition(0, 0, 0);
            var          expectedDirection = Vector4.CreateDirection(0.66519, 0.33259, -0.66851);
            const double epsilon           = 0.00001;
            var          comparer          = Vector4.GetEqualityComparer(epsilon);

            Assert.Equal(expectedOrigin, r.Origin, comparer);
            Assert.Equal(expectedDirection, r.Direction, comparer);
        }
        public SamplingStatus Sample(string operation, TraceId id)
        {
            lock (_lock)
            {
                if (OperationNameToSampler.TryGetValue(operation, out var sampler))
                {
                    return(sampler.Sample(operation, id));
                }

                if (OperationNameToSampler.Count < MaxOperations)
                {
                    var newSampler = new GuaranteedThroughputSampler(DefaultSampler.SamplingRate, LowerBound);
                    OperationNameToSampler[operation] = newSampler;
                    return(newSampler.Sample(operation, id));
                }

                return(DefaultSampler.Sample(operation, id));
            }
        }
        /// <summary>
        /// Updates the <see cref="GuaranteedThroughputSampler"/> for each operation.
        /// </summary>
        /// <param name="strategies">The parameters for operation sampling.</param>
        /// <returns><c>true</c>, if any samplers were updated.</returns>
        public bool Update(OperationSamplingParameters strategies)
        {
            lock (_lock)
            {
                var isUpdated = false;

                LowerBound = strategies.DefaultLowerBoundTracesPerSecond;
                ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.DefaultSamplingProbability);

                if (!defaultSampler.Equals(DefaultSampler))
                {
                    DefaultSampler.Close();
                    DefaultSampler = defaultSampler;
                    isUpdated      = true;
                }

                foreach (var strategy in strategies.PerOperationStrategies)
                {
                    var operation    = strategy.Operation;
                    var samplingRate = strategy.ProbabilisticSampling.SamplingRate;
                    if (OperationNameToSampler.TryGetValue(operation, out var sampler))
                    {
                        isUpdated = sampler.Update(samplingRate, LowerBound) || isUpdated;
                    }
                    else
                    {
                        if (OperationNameToSampler.Count < MaxOperations)
                        {
                            sampler = new GuaranteedThroughputSampler(samplingRate, LowerBound);
                            OperationNameToSampler[operation] = sampler;
                            isUpdated = true;
                        }
                        else
                        {
                            _logger.LogInformation("Exceeded the maximum number of operations {maxOperations} for per operations sampling", MaxOperations);
                        }
                    }
                }

                return(isUpdated);
            }
        }
Exemplo n.º 11
0
        public void TestCreateRayWhenCameraIsTransformed()
        {
            var c = new Camera(201, 101, Math.PI / 2);

            c.Transform =
                Transform.RotateY(Math.PI / 4) *
                Transform.Translate(0, -2, 5);

            var s = new DefaultSampler(new World(), c);
            var r = s.RayForPixel(100, 50);
            var expectedOrigin    = Vector4.CreatePosition(0, 2, -5);
            var expectedDirection = Vector4.CreateDirection(
                Math.Sqrt(2) / 2,
                0,
                -Math.Sqrt(2) / 2);

            const double epsilon  = 0.00001;
            var          comparer = Vector4.GetEqualityComparer(epsilon);

            Assert.Equal(expectedOrigin, r.Origin, comparer);
            Assert.Equal(expectedDirection, r.Direction, comparer);
        }
Exemplo n.º 12
0
        public void RateOneShouldAlwaysSampleTrue(long traceId)
        {
            var sampler = new DefaultSampler(NoSalt, 1f);

            Assert.True(sampler.Sample(traceId));
        }
Exemplo n.º 13
0
        public void RateZeroShouldntSampleTrue(long traceId)
        {
            var sampler = new DefaultSampler(NoSalt, 0f);

            Assert.False(sampler.Sample(traceId));
        }
Exemplo n.º 14
0
        public void ValidRateShouldntThrow(float rate)
        {
            var sampler = new DefaultSampler(NoSalt);

            Assert.DoesNotThrow(() => sampler.SamplingRate = rate);
        }
Exemplo n.º 15
0
        public void InvalidRateShouldThrow(float rate)
        {
            var sampler = new DefaultSampler(NoSalt);

            Assert.Throws <ArgumentOutOfRangeException>(() => sampler.SamplingRate = rate);
        }