remove unused files (#1041)
This commit is contained in:
parent
52a37b94dc
commit
852c06f68c
|
|
@ -1,126 +0,0 @@
|
|||
// <copyright file="ActivityProcessorPipelineBuilder.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry.Trace.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures exporting pipeline with chains of processors and exporter.
|
||||
/// </summary>
|
||||
public class ActivityProcessorPipelineBuilder
|
||||
{
|
||||
private Func<ActivityExporter, ActivityProcessor> lastProcessorFactory;
|
||||
private List<Func<ActivityProcessor, ActivityProcessor>> processorChain;
|
||||
|
||||
internal ActivityProcessorPipelineBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
internal ActivityExporter Exporter { get; private set; }
|
||||
|
||||
internal List<ActivityProcessor> Processors { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds chained processor to the pipeline. Processors are executed in the order they were added.
|
||||
/// </summary>
|
||||
/// <param name="processorFactory">Function that creates processor from the next one.</param>
|
||||
/// <returns>Returns <see cref="ActivityProcessorPipelineBuilder"/>.</returns>
|
||||
public ActivityProcessorPipelineBuilder AddProcessor(Func<ActivityProcessor, ActivityProcessor> processorFactory)
|
||||
{
|
||||
if (processorFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(processorFactory));
|
||||
}
|
||||
|
||||
if (this.processorChain == null)
|
||||
{
|
||||
this.processorChain = new List<Func<ActivityProcessor, ActivityProcessor>>();
|
||||
}
|
||||
|
||||
this.processorChain.Add(processorFactory);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures last processor that invokes exporter. When not set, <see cref="SimpleActivityProcessor"/> is used.
|
||||
/// </summary>
|
||||
/// <param name="processorFactory">Factory that creates exporting processor from the exporter.</param>
|
||||
/// <returns>Returns <see cref="ActivityProcessorPipelineBuilder"/>.</returns>
|
||||
public ActivityProcessorPipelineBuilder SetExportingProcessor(Func<ActivityExporter, ActivityProcessor> processorFactory)
|
||||
{
|
||||
this.lastProcessorFactory = processorFactory ?? throw new ArgumentNullException(nameof(processorFactory));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures exporter.
|
||||
/// </summary>
|
||||
/// <param name="exporter">Exporter instance.</param>
|
||||
/// <returns>Returns <see cref="ActivityProcessorPipelineBuilder"/>.</returns>
|
||||
public ActivityProcessorPipelineBuilder SetExporter(ActivityExporter exporter)
|
||||
{
|
||||
this.Exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
|
||||
return this;
|
||||
}
|
||||
|
||||
internal ActivityProcessor Build()
|
||||
{
|
||||
this.Processors = new List<ActivityProcessor>();
|
||||
|
||||
ActivityProcessor exportingProcessor = null;
|
||||
|
||||
// build or create default exporting processor
|
||||
if (this.lastProcessorFactory != null)
|
||||
{
|
||||
exportingProcessor = this.lastProcessorFactory.Invoke(this.Exporter);
|
||||
this.Processors.Add(exportingProcessor);
|
||||
}
|
||||
else if (this.Exporter != null)
|
||||
{
|
||||
exportingProcessor = new BatchingActivityProcessor(this.Exporter);
|
||||
this.Processors.Add(exportingProcessor);
|
||||
}
|
||||
|
||||
if (this.processorChain == null)
|
||||
{
|
||||
// if there is no chain, return exporting processor.
|
||||
if (exportingProcessor == null)
|
||||
{
|
||||
exportingProcessor = new NoopActivityProcessor();
|
||||
this.Processors.Add(exportingProcessor);
|
||||
}
|
||||
|
||||
return exportingProcessor;
|
||||
}
|
||||
|
||||
var next = exportingProcessor;
|
||||
|
||||
// build chain from the end to the beginning
|
||||
for (int i = this.processorChain.Count - 1; i >= 0; i--)
|
||||
{
|
||||
next = this.processorChain[i].Invoke(next);
|
||||
this.Processors.Add(next);
|
||||
}
|
||||
|
||||
// return the last processor in the chain - it will be called first
|
||||
return this.Processors[this.Processors.Count - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
// <copyright file="ActivityProcessorPipelineTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Testing.Export;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Tests.Impl.Trace.Config
|
||||
{
|
||||
public class ActivityProcessorPipelineTests
|
||||
{
|
||||
[Fact]
|
||||
public void PipelineBuilder_BadArgs()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ActivityProcessorPipelineBuilder().AddProcessor(null));
|
||||
Assert.Throws<ArgumentNullException>(() => new ActivityProcessorPipelineBuilder().SetExporter(null));
|
||||
Assert.Throws<ArgumentNullException>(() => new ActivityProcessorPipelineBuilder().SetExportingProcessor(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_Defaults()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
Assert.Null(builder.Exporter);
|
||||
Assert.Null(builder.Processors);
|
||||
|
||||
var processor = builder.Build();
|
||||
|
||||
Assert.Null(builder.Exporter);
|
||||
Assert.Single(builder.Processors);
|
||||
Assert.IsType<NoopActivityProcessor>(builder.Processors[0]);
|
||||
Assert.Same(processor, builder.Processors[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddExporter()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
var exporter = new TestActivityExporter(null);
|
||||
builder.SetExporter(exporter);
|
||||
|
||||
Assert.Same(exporter, builder.Exporter);
|
||||
|
||||
var processor = builder.Build();
|
||||
|
||||
Assert.Single(builder.Processors);
|
||||
Assert.IsType<BatchingActivityProcessor>(builder.Processors.Single());
|
||||
Assert.Same(processor, builder.Processors[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddExporterAndExportingProcessor()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
var exporter = new TestActivityExporter(null);
|
||||
builder.SetExporter(exporter);
|
||||
|
||||
bool processorFactoryCalled = false;
|
||||
builder.SetExportingProcessor(e =>
|
||||
{
|
||||
processorFactoryCalled = true;
|
||||
return new SimpleActivityProcessor(e);
|
||||
});
|
||||
|
||||
var processor = builder.Build();
|
||||
|
||||
Assert.Single(builder.Processors);
|
||||
Assert.True(processorFactoryCalled);
|
||||
Assert.IsType<SimpleActivityProcessor>(builder.Processors.Single());
|
||||
Assert.Same(processor, builder.Processors[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddExportingProcessor()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
bool processorFactoryCalled = false;
|
||||
var processor = new TestProcessor();
|
||||
builder.SetExportingProcessor(e =>
|
||||
{
|
||||
processorFactoryCalled = true;
|
||||
Assert.Null(e);
|
||||
return processor;
|
||||
});
|
||||
|
||||
Assert.Same(processor, builder.Build());
|
||||
|
||||
Assert.Single(builder.Processors);
|
||||
Assert.True(processorFactoryCalled);
|
||||
Assert.Same(processor, builder.Processors.Single());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddProcessor()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
bool processorFactoryCalled = false;
|
||||
var processor = new TestProcessor();
|
||||
builder.AddProcessor(e =>
|
||||
{
|
||||
processorFactoryCalled = true;
|
||||
return processor;
|
||||
});
|
||||
|
||||
Assert.Same(processor, builder.Build());
|
||||
|
||||
Assert.Single(builder.Processors);
|
||||
Assert.True(processorFactoryCalled);
|
||||
Assert.Same(processor, builder.Processors.Single());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddProcessorChain()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
bool processorFactory1Called = false;
|
||||
bool processorFactory2Called = false;
|
||||
bool processorFactory3Called = false;
|
||||
|
||||
builder
|
||||
.AddProcessor(next =>
|
||||
{
|
||||
processorFactory1Called = true;
|
||||
Assert.NotNull(next);
|
||||
return new TestProcessor(next, "1");
|
||||
})
|
||||
.AddProcessor(next =>
|
||||
{
|
||||
processorFactory2Called = true;
|
||||
Assert.NotNull(next);
|
||||
return new TestProcessor(next, "2");
|
||||
})
|
||||
.AddProcessor(next =>
|
||||
{
|
||||
processorFactory3Called = true;
|
||||
Assert.Null(next);
|
||||
return new TestProcessor(next, "3");
|
||||
});
|
||||
|
||||
var firstProcessor = (TestProcessor)builder.Build();
|
||||
|
||||
Assert.Equal(3, builder.Processors.Count);
|
||||
Assert.True(processorFactory1Called);
|
||||
Assert.True(processorFactory2Called);
|
||||
Assert.True(processorFactory3Called);
|
||||
|
||||
Assert.Equal("1", firstProcessor.Name);
|
||||
|
||||
var secondProcessor = (TestProcessor)firstProcessor.Next;
|
||||
Assert.Equal("2", secondProcessor.Name);
|
||||
var thirdProcessor = (TestProcessor)secondProcessor.Next;
|
||||
Assert.Equal("3", thirdProcessor.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PipelineBuilder_AddProcessorChainWithExporter()
|
||||
{
|
||||
var builder = new ActivityProcessorPipelineBuilder();
|
||||
|
||||
bool processorFactory1Called = false;
|
||||
bool processorFactory2Called = false;
|
||||
bool exportingFactory3Called = false;
|
||||
|
||||
builder
|
||||
.AddProcessor(next =>
|
||||
{
|
||||
processorFactory1Called = true;
|
||||
Assert.NotNull(next);
|
||||
return new TestProcessor(next, "1");
|
||||
})
|
||||
.AddProcessor(next =>
|
||||
{
|
||||
processorFactory2Called = true;
|
||||
Assert.NotNull(next);
|
||||
return new TestProcessor(next, "2");
|
||||
})
|
||||
.SetExportingProcessor(exporter =>
|
||||
{
|
||||
exportingFactory3Called = true;
|
||||
Assert.NotNull(exporter);
|
||||
return new SimpleActivityProcessor(exporter);
|
||||
})
|
||||
.SetExporter(new TestActivityExporter(null));
|
||||
|
||||
var firstProcessor = (TestProcessor)builder.Build();
|
||||
|
||||
Assert.Equal(3, builder.Processors.Count);
|
||||
Assert.True(processorFactory1Called);
|
||||
Assert.True(processorFactory2Called);
|
||||
Assert.True(exportingFactory3Called);
|
||||
|
||||
Assert.Equal("1", firstProcessor.Name);
|
||||
|
||||
var secondProcessor = (TestProcessor)firstProcessor.Next;
|
||||
Assert.Equal("2", secondProcessor.Name);
|
||||
var thirdProcessor = secondProcessor.Next;
|
||||
Assert.IsType<SimpleActivityProcessor>(thirdProcessor);
|
||||
}
|
||||
|
||||
private class TestProcessor : ActivityProcessor
|
||||
{
|
||||
public readonly ActivityProcessor Next;
|
||||
public readonly string Name;
|
||||
|
||||
public TestProcessor()
|
||||
{
|
||||
this.Name = null;
|
||||
this.Name = null;
|
||||
}
|
||||
|
||||
public TestProcessor(ActivityProcessor next, string name)
|
||||
{
|
||||
this.Next = next;
|
||||
this.Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue