Пример #1
0
        public IEnumerable <MetricWireModel> ConvertToJsonForSending(IMetricNameService nameService)
        {
            foreach (KeyValuePair <string, MetricDataWireModel> current in _unscopedStats)
            {
                var metric = MetricWireModel.BuildMetric(nameService, current.Key, null, current.Value);
                if (metric != null)
                {
                    yield return(metric);
                }
            }

            foreach (MetricWireModel model in _preCreatedUnscopedStats.Values)
            {
                //These already when through the rename service in the MetricWireModel
                //At some point this needs to be cleaned up. This is ugly.

                yield return(model);
            }

            foreach (KeyValuePair <string, MetricStatsDictionary <string, MetricDataWireModel> > currentScope in _scopedStats)
            {
                foreach (KeyValuePair <string, MetricDataWireModel> currentMetric in currentScope.Value)
                {
                    var metric = MetricWireModel.BuildMetric(nameService, currentMetric.Key, currentScope.Key, currentMetric.Value);
                    if (metric != null)
                    {
                        yield return(metric);
                    }
                }
            }
        }
Пример #2
0
        public void SetUp()
        {
            var configuration = Mock.Create <IConfiguration>();

            Mock.Arrange(() => configuration.CollectorSendDataOnExit).Returns(true);
            Mock.Arrange(() => configuration.CollectorSendDataOnExitThreshold).Returns(0);
            _configurationAutoResponder = new ConfigurationAutoResponder(configuration);

            _dataTransportService   = Mock.Create <IDataTransportService>();
            _metricBuilder          = WireModels.Utilities.GetSimpleMetricBuilder();
            _agentHealthReporter    = Mock.Create <IAgentHealthReporter>();
            _outOfBandMetricSources = new IOutOfBandMetricSource[] { (IOutOfBandMetricSource)_agentHealthReporter };
            _dnsStatic         = Mock.Create <IDnsStatic>();
            _processStatic     = Mock.Create <IProcessStatic>();
            _metricNameService = Mock.Create <IMetricNameService>();
            Mock.Arrange(() => _metricNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => name);

            var scheduler = Mock.Create <IScheduler>();

            Mock.Arrange(() => scheduler.ExecuteEvery(Arg.IsAny <Action>(), Arg.IsAny <TimeSpan>(), Arg.IsAny <TimeSpan?>()))
            .DoInstead <Action, TimeSpan, TimeSpan?>((action, harvestCycle, __) => { _harvestAction = action; _harvestCycle = harvestCycle; });
            _metricAggregator = new MetricAggregator(_dataTransportService, _metricBuilder, _metricNameService, _outOfBandMetricSources, _processStatic, scheduler);

            EventBus <AgentConnectedEvent> .Publish(new AgentConnectedEvent());
        }
 public TransactionTransformer(ITransactionMetricNameMaker transactionMetricNameMaker, ISegmentTreeMaker segmentTreeMaker, IMetricNameService metricNameService, IMetricAggregator metricAggregator, IConfigurationService configurationService, ITransactionTraceAggregator transactionTraceAggregator, ITransactionTraceMaker transactionTraceMaker, ITransactionEventAggregator transactionEventAggregator, ITransactionEventMaker transactionEventMaker, ITransactionAttributeMaker transactionAttributeMaker, IErrorTraceAggregator errorTraceAggregator, IErrorTraceMaker errorTraceMaker, IErrorEventAggregator errorEventAggregator, IErrorEventMaker errorEventMaker, ISqlTraceAggregator sqlTraceAggregator, ISqlTraceMaker sqlTraceMaker, ISpanEventAggregator spanEventAggregator, ISpanEventMaker spanEventMaker, IAgentTimerService agentTimerService,
                               IAdaptiveSampler adaptiveSampler, IErrorService errorService, ISpanEventAggregatorInfiniteTracing spanEventAggregatorInfiniteTracing)
 {
     _transactionMetricNameMaker = transactionMetricNameMaker;
     _segmentTreeMaker           = segmentTreeMaker;
     _metricNameService          = metricNameService;
     _metricAggregator           = metricAggregator;
     _configurationService       = configurationService;
     _transactionTraceAggregator = transactionTraceAggregator;
     _transactionTraceMaker      = transactionTraceMaker;
     _transactionEventAggregator = transactionEventAggregator;
     _transactionEventMaker      = transactionEventMaker;
     _transactionAttributeMaker  = transactionAttributeMaker;
     _errorTraceAggregator       = errorTraceAggregator;
     _errorTraceMaker            = errorTraceMaker;
     _errorEventAggregator       = errorEventAggregator;
     _errorEventMaker            = errorEventMaker;
     _sqlTraceAggregator         = sqlTraceAggregator;
     _sqlTraceMaker       = sqlTraceMaker;
     _spanEventAggregator = spanEventAggregator;
     _spanEventAggregatorInfiniteTracing = spanEventAggregatorInfiniteTracing;
     _spanEventMaker    = spanEventMaker;
     _agentTimerService = agentTimerService;
     _adaptiveSampler   = adaptiveSampler;
     _errorService      = errorService;
 }
        public void MergeScopedStats_VerifyRenaming()
        {
            IMetricNameService mNameService = Mock.Create <IMetricNameService>();

            Mock.Arrange(() => mNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => "IAmRenamed");
            var metric1     = MetricWireModel.BuildMetric(_metricNameService, "name", "myscope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));
            var engine      = new MetricStatsCollection();
            var scopedStats = new MetricStatsDictionary <string, MetricDataWireModel>();

            scopedStats[metric1.MetricName.Name] = metric1.Data;
            engine.MergeScopedStats(metric1.MetricName.Scope, scopedStats);
            IEnumerable <MetricWireModel> stats = engine.ConvertToJsonForSending(mNameService);
            var count = 0;

            foreach (MetricWireModel current in stats)
            {
                count++;
                Assert.AreEqual("IAmRenamed", current.MetricName.Name);
                Assert.AreEqual("myscope", current.MetricName.Scope);
                Assert.AreEqual(1, current.Data.Value0);
                Assert.AreEqual(3, current.Data.Value1);
                Assert.AreEqual(2, current.Data.Value2);
            }
            Assert.AreEqual(1, count);
        }
Пример #5
0
        public Agent(ITransactionService transactionService, ITransactionTransformer transactionTransformer,
                     IThreadPoolStatic threadPoolStatic, ITransactionMetricNameMaker transactionMetricNameMaker, IPathHashMaker pathHashMaker,
                     ICatHeaderHandler catHeaderHandler, IDistributedTracePayloadHandler distributedTracePayloadHandler,
                     ISyntheticsHeaderHandler syntheticsHeaderHandler, ITransactionFinalizer transactionFinalizer,
                     IBrowserMonitoringPrereqChecker browserMonitoringPrereqChecker, IBrowserMonitoringScriptMaker browserMonitoringScriptMaker,
                     IConfigurationService configurationService, IAgentHealthReporter agentHealthReporter, IAgentTimerService agentTimerService,
                     IMetricNameService metricNameService, Api.ITraceMetadataFactory traceMetadataFactory, ICATSupportabilityMetricCounters catMetricCounters)
        {
            _transactionService         = transactionService;
            _transactionTransformer     = transactionTransformer;
            _threadPoolStatic           = threadPoolStatic;
            _transactionMetricNameMaker = transactionMetricNameMaker;
            _pathHashMaker    = pathHashMaker;
            _catHeaderHandler = catHeaderHandler;
            _distributedTracePayloadHandler = distributedTracePayloadHandler;
            _syntheticsHeaderHandler        = syntheticsHeaderHandler;
            _transactionFinalizer           = transactionFinalizer;
            _browserMonitoringPrereqChecker = browserMonitoringPrereqChecker;
            _browserMonitoringScriptMaker   = browserMonitoringScriptMaker;
            _configurationService           = configurationService;
            _agentHealthReporter            = agentHealthReporter;
            _agentTimerService    = agentTimerService;
            _metricNameService    = metricNameService;
            _traceMetadataFactory = traceMetadataFactory;
            _catMetricCounters    = catMetricCounters;

            Instance = this;
        }
        public void SetUp()
        {
            _localConfig = new configuration();
            _localConfig.distributedTracing.enabled = true;
            _serverConfig  = new ServerConfiguration();
            _runTimeConfig = new RunTimeConfiguration();
            _defaultConfig = new TestableDefaultConfiguration(Mock.Create <IEnvironment>(), _localConfig, _serverConfig, _runTimeConfig,
                                                              new SecurityPoliciesConfiguration(), Mock.Create <IProcessStatic>(), Mock.Create <IHttpRuntimeStatic>(), Mock.Create <IConfigurationManagerStatic>(),
                                                              Mock.Create <IDnsStatic>());

            _transactionMetricNameMaker = Mock.Create <ITransactionMetricNameMaker>();
            Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(Arg.Matches <ITransactionName>(txName => txName.IsWeb)))
            .Returns(new TransactionMetricName("WebTransaction", "TransactionName"));
            Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(Arg.Matches <ITransactionName>(txName => !txName.IsWeb))).Returns(new TransactionMetricName("OtherTransaction", "TransactionName"));

            _transactionSegmentState = Mock.Create <ITransactionSegmentState>();
            Mock.Arrange(() => _transactionSegmentState.GetRelativeTime()).Returns(() => TimeSpan.Zero);
            Mock.Arrange(() => _transactionSegmentState.AttribDefs).Returns(() => new AttributeDefinitions(new AttributeFilter(new AttributeFilter.Settings())));

            _segmentTreeMaker = Mock.Create <ISegmentTreeMaker>();

            _metricNameService = Mock.Create <IMetricNameService>();

            _metricBuilder    = Mock.Create <IMetricBuilder>();
            _metricAggregator = Mock.Create <IMetricAggregator>();

            _configurationService = Mock.Create <IConfigurationService>();
            Mock.Arrange(() => _configurationService.Configuration).Returns(_defaultConfig);

            _transactionTraceAggregator = Mock.Create <ITransactionTraceAggregator>();
            _transactionTraceMaker      = Mock.Create <ITransactionTraceMaker>();
            _transactionEventAggregator = Mock.Create <ITransactionEventAggregator>();
            _transactionEventMaker      = Mock.Create <ITransactionEventMaker>();
            _transactionAttributeMaker  = Mock.Create <ITransactionAttributeMaker>();
            _errorTraceAggregator       = Mock.Create <IErrorTraceAggregator>();
            _errorTraceMaker            = Mock.Create <IErrorTraceMaker>();
            _errorEventAggregator       = Mock.Create <IErrorEventAggregator>();
            _errorEventMaker            = Mock.Create <IErrorEventMaker>();
            _sqlTraceAggregator         = Mock.Create <ISqlTraceAggregator>();
            _sqlTraceMaker = Mock.Create <ISqlTraceMaker>();

            _spanEventAggregator = Mock.Create <ISpanEventAggregator>();
            Mock.Arrange(() => _spanEventAggregator.IsServiceEnabled).Returns(() => _defaultConfig != null && _defaultConfig.SpanEventsEnabled && _defaultConfig.SpanEventsMaxSamplesStored > 0 && _defaultConfig.DistributedTracingEnabled);
            Mock.Arrange(() => _spanEventAggregator.IsServiceAvailable).Returns(() => _defaultConfig != null && _defaultConfig.SpanEventsEnabled && _defaultConfig.SpanEventsMaxSamplesStored > 0 && _defaultConfig.DistributedTracingEnabled);

            _spanEventAggregatorInfiniteTracing = Mock.Create <ISpanEventAggregatorInfiniteTracing>();
            Mock.Arrange(() => _spanEventAggregatorInfiniteTracing.IsServiceEnabled).Returns(() => !string.IsNullOrWhiteSpace(_defaultConfig?.InfiniteTracingTraceObserverHost));
            Mock.Arrange(() => _spanEventAggregatorInfiniteTracing.IsServiceAvailable).Returns(() => !string.IsNullOrWhiteSpace(_defaultConfig?.InfiniteTracingTraceObserverHost));

            _spanEventMaker        = Mock.Create <ISpanEventMaker>();
            _customEventAggregator = Mock.Create <ICustomEventAggregator>();
            _errorService          = Mock.Create <IErrorService>();

            _attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            _agentTimerService      = Mock.Create <IAgentTimerService>();
            _transactionTransformer = new TransactionTransformer(_transactionMetricNameMaker, _segmentTreeMaker, _metricNameService, _metricAggregator, _configurationService, _transactionTraceAggregator, _transactionTraceMaker, _transactionEventAggregator, _transactionEventMaker, _transactionAttributeMaker, _errorTraceAggregator, _errorTraceMaker, _errorEventAggregator, _errorEventMaker, _sqlTraceAggregator, _sqlTraceMaker, _spanEventAggregator, _spanEventMaker, _agentTimerService, Mock.Create <IAdaptiveSampler>(), _errorService, _spanEventAggregatorInfiniteTracing);
            _customEventTransformer = new CustomEventTransformer(_configurationService, _customEventAggregator, _attribDefSvc);
        }
        public void SetUp()
        {
            _metricNameService = Mock.Create <IMetricNameService>();
            Mock.Arrange(() => _metricNameService.RenameTransaction(Arg.IsAny <TransactionMetricName>()))
            .Returns(name => name);

            _transactionMetricNameMaker = new TransactionMetricNameMaker(_metricNameService);
        }
Пример #8
0
        public void SetUp()
        {
            _environment                = Mock.Create <IEnvironment>();
            _processStatic              = Mock.Create <IProcessStatic>();
            _httpRuntimeStatic          = Mock.Create <IHttpRuntimeStatic>();
            _configurationManagerStatic = Mock.Create <IConfigurationManagerStatic>();
            _dnsStatic = Mock.Create <IDnsStatic>();
            _securityPoliciesConfiguration = new SecurityPoliciesConfiguration();

            _runTimeConfiguration = new RunTimeConfiguration();
            _serverConfig         = new ServerConfiguration();

            SetLocalConfigurationDefaults();
            PublishConfig();

            _configAutoResponder = new ConfigurationAutoResponder(_config);

            _configurationService = Mock.Create <IConfigurationService>();
            Mock.Arrange(() => _configurationService.Configuration).Returns(() => _config);

            _attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            _metricNameSvc = new MetricNameService();
            _transactionMetricNameMaker = new TransactionMetricNameMaker(_metricNameSvc);

            _transactionAttribMaker = new TransactionAttributeMaker(_configurationService, _attribDefSvc);

            _spanEventMaker  = new SpanEventMaker(_attribDefSvc, _configurationService);
            _databaseService = new DatabaseService(Mock.Create <ICacheStatsReporter>());

            _transactionEventMaker = new TransactionEventMaker(_attribDefSvc);


            _transactionGuid = GuidGenerator.GenerateNewRelicGuid();
            _startTime       = new DateTime(2018, 7, 18, 7, 0, 0, DateTimeKind.Utc); // unixtime = 1531897200000

            // Generic Segments
            _baseGenericSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseGenericSegment.SetSegmentData(new SimpleSegmentData(SegmentName));

            _childGenericSegment = new Segment(CreateTransactionSegmentState(4, 3, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _childGenericSegment.SetSegmentData(new SimpleSegmentData(SegmentName));

            // Datastore Segments
            _connectionInfo       = new ConnectionInfo("localhost", "1234", "default", "maininstance");
            _parsedSqlStatement   = SqlParser.GetParsedDatabaseStatement(DatastoreVendor.MSSQL, System.Data.CommandType.Text, ShortQuery);
            _obfuscatedSql        = _databaseService.GetObfuscatedSql(ShortQuery, DatastoreVendor.MSSQL);
            _baseDatastoreSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseDatastoreSegment.SetSegmentData(new DatastoreSegmentData(_databaseService, _parsedSqlStatement, ShortQuery, _connectionInfo));

            // Http Segments
            _baseHttpSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseHttpSegment.SetSegmentData(new ExternalSegmentData(new Uri(HttpUri), HttpMethod));
        }
        public void SetUp()
        {
            // Mocks
            _transactionMetricNameMaker = Mock.Create <ITransactionMetricNameMaker>();
            Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(Arg.Matches <ITransactionName>(txName => txName.IsWeb)))
            .Returns(new TransactionMetricName("WebTransaction", "TransactionName"));
            Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(Arg.Matches <ITransactionName>(txName => !txName.IsWeb))).Returns(new TransactionMetricName("OtherTransaction", "TransactionName"));

            _metricAggregator = Mock.Create <IMetricAggregator>();

            _configuration        = GetDefaultConfiguration();
            _configurationService = Mock.Create <IConfigurationService>();
            Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration);

            _transactionTraceAggregator         = Mock.Create <ITransactionTraceAggregator>();
            _transactionTraceMaker              = Mock.Create <ITransactionTraceMaker>();
            _transactionEventAggregator         = Mock.Create <ITransactionEventAggregator>();
            _transactionEventMaker              = Mock.Create <ITransactionEventMaker>();
            _transactionAttributeMaker          = Mock.Create <ITransactionAttributeMaker>();
            _errorTraceAggregator               = Mock.Create <IErrorTraceAggregator>();
            _errorTraceMaker                    = Mock.Create <IErrorTraceMaker>();
            _errorEventAggregator               = Mock.Create <IErrorEventAggregator>();
            _errorEventMaker                    = Mock.Create <IErrorEventMaker>();
            _spanEventAggregator                = Mock.Create <ISpanEventAggregator>();
            _spanEventAggregatorInfiniteTracing = Mock.Create <ISpanEventAggregatorInfiniteTracing>();
            _spanEventMaker    = Mock.Create <ISpanEventMaker>();
            _agentTimerService = Mock.Create <IAgentTimerService>();

            _attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));
            _errorService = Mock.Create <IErrorService>();

            // Non-Mocks
            _segmentTreeMaker = new SegmentTreeMaker();

            _metricNameService = Mock.Create <IMetricNameService>();
            Mock.Arrange(() => _metricNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => name);

            var dataTransportService = Mock.Create <DataTransport.IDataTransportService>();
            var scheduler            = Mock.Create <Time.IScheduler>();
            var processStatic        = Mock.Create <SystemInterfaces.IProcessStatic>();
            var agentHealthReporter  = Mock.Create <AgentHealth.IAgentHealthReporter>();

            _sqlTraceAggregator = new SqlTraceAggregator(dataTransportService, scheduler, processStatic, agentHealthReporter);

            _transactionAttributeMaker = new TransactionAttributeMaker(_configurationService, _attribDefSvc);

            _sqlTraceMaker = new SqlTraceMaker(_configurationService, _attribDefSvc, new DatabaseService(Mock.Create <ICacheStatsReporter>()));

            // create TransactionTransformer
            _transactionTransformer = new TransactionTransformer(_transactionMetricNameMaker, _segmentTreeMaker, _metricNameService, _metricAggregator, _configurationService, _transactionTraceAggregator, _transactionTraceMaker, _transactionEventAggregator, _transactionEventMaker, _transactionAttributeMaker, _errorTraceAggregator, _errorTraceMaker, _errorEventAggregator, _errorEventMaker, _sqlTraceAggregator, _sqlTraceMaker, _spanEventAggregator, _spanEventMaker, _agentTimerService, Mock.Create <IAdaptiveSampler>(), _errorService, _spanEventAggregatorInfiniteTracing);
        }
        public MetricAggregator(IDataTransportService dataTransportService, IMetricBuilder metricBuilder, IMetricNameService metricNameService, IEnumerable <IOutOfBandMetricSource> outOfBandMetricSources, IProcessStatic processStatic, IScheduler scheduler)
            : base(dataTransportService, scheduler, processStatic)
        {
            _metricBuilder          = metricBuilder;
            _metricNameService      = metricNameService;
            _outOfBandMetricSources = outOfBandMetricSources;

            foreach (var source in outOfBandMetricSources)
            {
                if (source != null)
                {
                    source.RegisterPublishMetricHandler(Collect);
                }
            }

            _metricStatsEngineQueue = CreateMetricStatsEngineQueue();
        }
 public void SetUp()
 {
     _metricNameService = Mock.Create <IMetricNameService>();
     Mock.Arrange(() => _metricNameService.RenameMetric(Arg.IsAny <string>())).Returns <string>(name => name);
     _metricBuilder = new MetricWireModel.MetricBuilder(_metricNameService);
 }
Пример #12
0
 public TransactionMetricNameMaker(IMetricNameService metricNameService)
 {
     _metricNameService = metricNameService;
 }