Beispiel #1
0
 /// <summary>
 /// CalcSizeOfSerializedThrift calculates the size in bytes that a Thrift object will take up.
 /// </summary>
 /// <param name="thriftBase">the base Thrift object to calculate the size of</param>
 /// <returns></returns>
 private async Task <int> CalcSizeOfSerializedThrift(TBase thriftBase)
 {
     _thriftBuffer.Reset();
     try {
         await thriftBase.WriteAsync(_thriftProtocol, CancellationToken.None);
     } catch (Exception e) {
         throw new Exception("failed to calculate the size of a serialized thrift object", e);
     }
     return(_thriftBuffer.GetBuffer().Length);
 }
Beispiel #2
0
        public async void EmitBatchOverhead_ShouldNotGoOverOverheadConstant()
        {
            var transport       = new TMemoryBuffer();
            var protocolFactory = new TCompactProtocol.Factory();
            var client          = new Agent.Client(protocolFactory.GetProtocol(transport));

            var jSpan     = new JaegerSpan(10, 11, 12, 13, "opName", 0, 1234, 1235);
            var jSpanSize = CalcSizeOfSerializedThrift(jSpan);

            var tests = new[] { 1, 2, 14, 15, 377, 500, 65000, 0xFFFF };

            foreach (var test in tests)
            {
                transport.Reset();
                var batch       = new List <JaegerSpan>();
                var processTags = new List <JaegerTag>();
                for (var j = 0; j < test; j++)
                {
                    batch.Add(jSpan);
                    processTags.Add(new JaegerTag("testingTag", TagType.BINARY)
                    {
                        VBinary = new byte[] { 0x20 }
                    });
                }

                var jProcess = new JaegerProcess("testing")
                {
                    Tags = processTags
                };
                await client.emitBatchAsync(new JaegerBatch(jProcess, batch), CancellationToken.None);

                var jProcessSize = CalcSizeOfSerializedThrift(jProcess);

                var overhead = transport.GetBuffer().Length - test * jSpanSize - jProcessSize;
                Assert.True(overhead <= TransportConstants.UdpEmitBatchOverhead);
            }
        }
Beispiel #3
0
 public int GetSize(TBase thriftBase)
 {
     _memoryTransport.Reset();
     thriftBase.WriteAsync(ProtocolFactory.GetProtocol(_memoryTransport), CancellationToken.None).GetAwaiter().GetResult();
     return(_memoryTransport.GetBuffer().Length);
 }