Пример #1
0
 public void CanUseDataDirectory()
 {
     var storage = new FolderFileStorage(DATA_DIRECTORY_QUEUE_FOLDER);
     Assert.NotNull(storage.Folder);
     Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder);
     Assert.True(storage.Folder.EndsWith("Queue\\"), storage.Folder);
 }
Пример #2
0
        public GeoTests() {
            var dataDirectory = PathHelper.ExpandPath(".\\");
            var storage = new FolderFileStorage(dataDirectory);

            if (!storage.ExistsAsync(MindMaxGeoIPResolver.GEO_IP_DATABASE_PATH).Result) {
                var job = new DownloadGeoIPDatabaseJob(storage).Run();
                Assert.NotNull(job);
                Assert.True(job.IsSuccess);
            }

            _resolver = new MindMaxGeoIPResolver(storage);
        }
Пример #3
0
        private static async Task<IGeoIpService> GetResolverAsync(ILoggerFactory loggerFactory) {
            if (_service != null)
                return _service;

            var dataDirectory = PathHelper.ExpandPath(".\\");
            var storage = new FolderFileStorage(dataDirectory);

            if (!await storage.ExistsAsync(MaxMindGeoIpService.GEO_IP_DATABASE_PATH)) {
                var job = new DownloadGeoIPDatabaseJob(new InMemoryCacheClient(), storage, loggerFactory);
                var result = await job.RunAsync();
                Assert.NotNull(result);
                Assert.True(result.IsSuccess);
            }

            return _service = new MaxMindGeoIpService(storage, loggerFactory.CreateLogger<MaxMindGeoIpService>());
        }
Пример #4
0
        private async Task<IGeoIPResolver> GetResolverAsync() {
            if (_resolver != null)
                return _resolver;

            var dataDirectory = PathHelper.ExpandPath(".\\");
            var storage = new FolderFileStorage(dataDirectory);

            if (!await storage.ExistsAsync(MindMaxGeoIPResolver.GEO_IP_DATABASE_PATH)) {
                var job = new DownloadGeoIPDatabaseJob(new InMemoryCacheClient(), storage);
                var result = await job.RunAsync();
                Assert.NotNull(result);
                Assert.True(result.IsSuccess);
            }

            return _resolver = new MindMaxGeoIPResolver(storage);
        }
Пример #5
0
        public async Task GeneratePerformanceData() {
            var currentBatchCount = 0;
            var parserPluginManager = IoC.GetInstance<EventParserPluginManager>();
            var dataDirectory = Path.GetFullPath(@"..\..\Pipeline\Data\");
            
            foreach (var file in Directory.GetFiles(dataDirectory))
                File.Delete(file);
            
            Dictionary<string, UserInfo> _mappedUsers = new Dictionary<string, UserInfo>();
            Dictionary<string, string> _mappedIPs = new Dictionary<string, string>();

            var storage = new FolderFileStorage(Path.GetFullPath(@"..\..\..\"));
            foreach (var file in await storage.GetFileListAsync(@"Api\App_Data\storage\q\*")) {
                var eventPostInfo = await storage.GetObjectAsync<EventPostInfo>(file.Path);
                byte[] data = eventPostInfo.Data;
                if (!String.IsNullOrEmpty(eventPostInfo.ContentEncoding))
                    data = data.Decompress(eventPostInfo.ContentEncoding);

                var encoding = Encoding.UTF8;
                if (!String.IsNullOrEmpty(eventPostInfo.CharSet))
                    encoding = Encoding.GetEncoding(eventPostInfo.CharSet);

                string input = encoding.GetString(data);
                var events = parserPluginManager.ParseEvents(input, eventPostInfo.ApiVersion, eventPostInfo.UserAgent);
                
                foreach (var ev in events) {
                    ev.Date = new DateTimeOffset(new DateTime(2020, 1, 1));
                    ev.ProjectId = null;
                    ev.OrganizationId = null;
                    ev.StackId = null;

                    if (ev.Message != null)
                        ev.Message = RandomData.GetSentence();

                    var keysToRemove = ev.Data.Keys.Where(k => !k.StartsWith("@") && k != "MachineName" && k != "job" && k != "host" && k != "process").ToList();
                    foreach (var key in keysToRemove)
                        ev.Data.Remove(key);

                    ev.Data.Remove(Event.KnownDataKeys.UserDescription);
                    var identity = ev.GetUserIdentity();
                    if (identity != null) {
                        if (!_mappedUsers.ContainsKey(identity.Identity))
                            _mappedUsers.Add(identity.Identity, new UserInfo(Guid.NewGuid().ToString(), currentBatchCount.ToString()));

                        ev.SetUserIdentity(_mappedUsers[identity.Identity]);
                    }
                    
                    var request = ev.GetRequestInfo();
                    if (request != null) {
                        request.Cookies?.Clear();
                        request.PostData = null;
                        request.QueryString?.Clear();
                        request.Referrer = null;
                        request.Host = RandomData.GetIp4Address();
                        request.Path = $"/{RandomData.GetWord(false)}/{RandomData.GetWord(false)}";
                        request.Data.Clear();

                        if (request.ClientIpAddress != null) {
                            if (!_mappedIPs.ContainsKey(request.ClientIpAddress))
                                _mappedIPs.Add(request.ClientIpAddress, RandomData.GetIp4Address());

                            request.ClientIpAddress = _mappedIPs[request.ClientIpAddress];
                        }
                    }

                    InnerError error = ev.GetError();
                    while (error != null) {
                        error.Message = RandomData.GetSentence();
                        error.Data.Clear();
                        (error as Error)?.Modules.Clear();

                        error = error.Inner;
                    }

                    var environment = ev.GetEnvironmentInfo();
                    environment?.Data.Clear();
                }
                
                // inject random session start events.
                if (currentBatchCount % 10 == 0)
                    events.Insert(0, events[0].ToSessionStartEvent());

                await storage.SaveObjectAsync($"{dataDirectory}\\{currentBatchCount++}.json", events);
            }
        }