Example #1
0
        public async Task <IncidentEntity> CreateAsync(ParsedIncident input)
        {
            var groupEntity = await _aggregationProvider.GetAsync(input);

            var affectedPath = _pathProvider.Get(input);

            using (_logger.Scope("Creating incident for parsed incident with path {AffectedComponentPath}.", affectedPath))
            {
                var incidentEntity = new IncidentEntity(
                    input.Id,
                    groupEntity,
                    affectedPath,
                    input.AffectedComponentStatus,
                    input.StartTime,
                    input.EndTime);

                await _table.InsertOrReplaceAsync(incidentEntity);

                if (incidentEntity.AffectedComponentStatus > groupEntity.AffectedComponentStatus)
                {
                    _logger.LogInformation("Incident {IncidentRowKey} has a greater severity than incident group {GroupRowKey} it was just linked to ({NewSeverity} > {OldSeverity}), updating group's severity.",
                                           incidentEntity.RowKey, groupEntity.RowKey, (ComponentStatus)incidentEntity.AffectedComponentStatus, (ComponentStatus)groupEntity.AffectedComponentStatus);
                    groupEntity.AffectedComponentStatus = incidentEntity.AffectedComponentStatus;
                    await _table.ReplaceAsync(groupEntity);
                }

                return(incidentEntity);
            }
        }
Example #2
0
        public async Task <TAggregationEntity> GetAsync(ParsedIncident input)
        {
            TAggregationEntity aggregationEntity = null;

            var possiblePath = _aggregationPathProvider.Get(input);
            // Find an aggregation to link to
            var possibleAggregationsQuery = _table
                                            .CreateQuery <TAggregationEntity>()
                                            .Where(e =>
                                                   // The aggregation must affect the same path
                                                   e.AffectedComponentPath == possiblePath &&
                                                   // The aggregation must begin before or at the same time
                                                   e.StartTime <= input.StartTime);

            // The aggregation must cover the same time period
            if (input.IsActive)
            {
                // An active input can only be linked to an active aggregation
                possibleAggregationsQuery = possibleAggregationsQuery
                                            .Where(e => e.IsActive);
            }
            else
            {
                // An inactive input can be linked to an active aggregation or an inactive aggregation that ends after it
                possibleAggregationsQuery = possibleAggregationsQuery
                                            .Where(e =>
                                                   e.IsActive ||
                                                   e.EndTime >= input.EndTime);
            }

            var possibleAggregations = possibleAggregationsQuery
                                       .ToList();

            _logger.LogInformation("Found {AggregationCount} possible aggregations to link entity to with path {AffectedComponentPath}.", possibleAggregations.Count(), possiblePath);
            foreach (var possibleAggregation in possibleAggregations)
            {
                if (await _strategy.CanBeAggregatedByAsync(input, possibleAggregation))
                {
                    _logger.LogInformation("Linking entity to aggregation.");
                    aggregationEntity = possibleAggregation;
                    break;
                }
            }

            if (aggregationEntity == null)
            {
                _logger.LogInformation("Could not find existing aggregation to link to, creating new aggregation to link entity to.");
                aggregationEntity = await _aggregationFactory.CreateAsync(input);

                _logger.LogInformation("Created new aggregation {AggregationRowKey} to link entity to.", aggregationEntity.RowKey);
            }

            return(aggregationEntity);
        }
Example #3
0
        public async Task <EventEntity> CreateAsync(ParsedIncident input)
        {
            var affectedPath = _pathProvider.Get(input);

            using (_logger.Scope("Creating event for parsed incident with path {AffectedComponentPath}.", affectedPath))
            {
                var entity = new EventEntity(affectedPath, input.StartTime);
                await _table.InsertOrReplaceAsync(entity);

                return(entity);
            }
        }
Example #4
0
        public async Task <IncidentGroupEntity> CreateAsync(ParsedIncident input)
        {
            var eventEntity = await _aggregationProvider.GetAsync(input);

            var affectedPath = _pathProvider.Get(input);

            using (_logger.Scope("Creating incident for parsed incident with path {AffectedComponentPath}.", affectedPath))
            {
                var incidentGroupEntity = new IncidentGroupEntity(
                    eventEntity,
                    affectedPath,
                    (ComponentStatus)input.AffectedComponentStatus,
                    input.StartTime);

                await _table.InsertOrReplaceAsync(incidentGroupEntity);

                return(incidentGroupEntity);
            }
        }