private async void DisplaySearchResult(string searchStr) { SearchExportArgs jobArgs = new SearchExportArgs(); if (this.searchEarliestTime != null) { jobArgs.EarliestTime = this.searchEarliestTime; } if (this.searchLatestTime != null) { jobArgs.LatestTime = this.searchLatestTime; } using (SearchResultStream resultStream = await MainPage.SplunkService.ExportSearchResultsAsync(searchStr, jobArgs)) { titleGrid.Visibility = Visibility.Visible; this.allResults.Clear(); Task task = this.GetResultTask(resultStream); bool showFirstPage = false; do { if (this.allResults.Count > 0) { if (!showFirstPage && this.ShowResultPage(this.allResults, 0, this.itemsPerPage)) { showFirstPage = true; } if (this.currentShownPageIndex < 0) { ShowPagingLink(0); } } await Task.Delay(1000); } while (!(task.Status == TaskStatus.RanToCompletion || task.Status == TaskStatus.Faulted || task.Status == TaskStatus.Canceled)); if (!showFirstPage) { this.ShowResultPage(this.allResults, 0, this.itemsPerPage); } if (this.currentShownPageIndex < 0) { ShowPagingLink(0); } this.PageContentReset(); } }
public void RemoteServerList() { var array = "first,second";// new string[] { "first", "second" }; var args1 = new SearchExportArgs("") { RemoteServerList = array, }; Assert.Equal("first,second", args1.RemoteServerList); var args2 = new JobArgs("") { RemoteServerList = array, }; Assert.Equal("first,second", args2.RemoteServerList); }
void CanConstructSearchExportArgs() { var args = new SearchExportArgs(); Assert.Equal( "auto_cancel=0; " + "auto_finalize_ec=0; " + "auto_pause=0; " + "count=100; " + "earliest_time=null; " + "enable_lookups=1; " + "f=null; " + "force_bundle_replication=0; " + "id=null; " + "index_earliest=null; " + "index_latest=null; " + "latest_time=null; " + "max_lines=0; " + "max_time=0; " + "namespace=null; " + "now=null; " + "offset=0; " + "output_time_format=null; " + "reduce_freq=0; " + "reload_macros=1; " + "remote_server_list=null; " + "rf=null; " + "rt_blocking=0; " + "rt_indexfilter=0; " + "rt_maxblocksecs=60; " + "rt_queue_size=10000; " + "search=null; " + "search_listener=null; " + "search_mode=normal; " + "segmentation=raw; " + "sync_bundle_replication=0; " + "time_format=null; " + "timeout=86400; " + "truncation_mode=abstract", args.ToString()); Assert.Equal(0, args.ToArray().Length); }
/// <summary> /// /// </summary> /// <param name="args"> /// </param> /// <returns> /// An object for reading a stream of <see cref="SearchResults"/>. /// </returns> /// <remarks> /// This method uses the /// </remarks> public async Task<SearchResultsReader> SearchExportAsync(SearchExportArgs args) { Contract.Requires<ArgumentNullException>(args != null, "args"); var response = await this.Context.GetAsync(this.Namespace, SearchJobsExport, args); try { await response.EnsureStatusCodeAsync(HttpStatusCode.OK); //// DSN: The search results reader is a stream of SearchResultSet objects. TODO: Explanation... //// FJR: We should probably return a stream here and keep the parsers separate. That lets someone //// else plug in and use their own parser if they really want to. We don't particularly support the //// scenario, but it doesn't block the user. return await SearchResultsReader.CreateAsync(response); // Transfers response ownership } catch { response.Dispose(); throw; } }
public async Task CanExportSearchResultsToObservable() { using (var service = await SdkHelper.CreateService()) { var args = new SearchExportArgs { Count = 0 }; using (SearchResultStream stream = await service.ExportSearchResultsAsync("search index=_internal | tail 100", args)) { var manualResetEvent = new ManualResetEvent(true); var results = new List<SearchResult>(); var exception = (Exception)null; int readCount = 0; stream.Subscribe(new Observer<SearchResult>( onNext: (result) => { var memberNames = result.GetDynamicMemberNames(); var count = stream.FieldNames.Intersect(memberNames).Count(); Assert.Equal(count, memberNames.Count()); if (stream.IsFinal) { results.Add(result); } readCount++; }, onCompleted: () => { manualResetEvent.Set(); }, onError: (e) => { exception = new ApplicationException("SearchPreviewStream error: " + e.Message, e); manualResetEvent.Set(); })); manualResetEvent.Reset(); manualResetEvent.WaitOne(); Assert.Null(exception); Assert.True(stream.IsFinal); Assert.Equal(100, results.Count); Assert.Equal(stream.ReadCount, readCount); } await service.LogOffAsync(); } }
public async Task CanExportSearchResultsToEnumerable() { using (var service = await SdkHelper.CreateService()) { const string search = "search index=_internal | tail 100"; var args = new SearchExportArgs { Count = 0 }; using (SearchResultStream stream = await service.ExportSearchResultsAsync(search, args)) { var results = new List<SearchResult>(); foreach (SearchResult result in stream) { results.Add(result); } } await service.LogOffAsync(); } }
public async Task CanExportSearchPreviewsToObservable() { using (var service = await SdkHelper.CreateService()) { const string search = "search index=_internal | sort time |head 5000 | stats count by method"; var args = new SearchExportArgs() { Count = 0, EarliestTime = "-24h" }; using (SearchPreviewStream stream = await service.ExportSearchPreviewsAsync(search, args)) { var manualResetEvent = new ManualResetEvent(true); var results = new List<SearchResult>(); var exception = (Exception)null; stream.Subscribe(new Observer<SearchPreview>( onNext: (preview) => { Assert.Equal<IEnumerable<string>>(new ReadOnlyCollection<string>(new string[] { "method", "count", }), preview.FieldNames); if (preview.IsFinal) { results.AddRange(preview.Results); } }, onCompleted: () => { manualResetEvent.Set(); }, onError: (e) => { exception = new ApplicationException("SearchPreviewStream error: " + e.Message, e); manualResetEvent.Set(); })); manualResetEvent.Reset(); manualResetEvent.WaitOne(); Assert.Null(exception); Assert.NotEmpty(results); Assert.True(stream.ReadCount >= 1); } await service.LogOffAsync(); } }
public async Task CanExportSearchPreviewsToEnumerable() { using (var service = await SdkHelper.CreateService()) { const string search = "search index=_internal | sort time |head 5000 | stats count by method"; var args = new SearchExportArgs() { Count = 0, EarliestTime = "-7d" }; Stopwatch watch = new Stopwatch(); watch.Start(); using (SearchPreviewStream stream = await service.ExportSearchPreviewsAsync(search, args)) { var results = new List<SearchResult>(); foreach (var preview in stream) { Assert.Equal<IEnumerable<string>>(new ReadOnlyCollection<string>(new string[] { "method", "count", }), preview.FieldNames); if (preview.IsFinal) { results.AddRange(preview.Results); } } watch.Stop(); Console.WriteLine("spent {0} to read all stream", watch.Elapsed.TotalSeconds); Console.WriteLine("stream.ReadCount={0}", stream.ReadCount); Assert.True(stream.ReadCount >= 1); Assert.NotEmpty(results); } await service.LogOffAsync(); } }
public async Task CanCancelExportSearchResults() { using (var service = await SdkHelper.CreateService()) { const string search = "search index=_internal | tail 100"; var args = new SearchExportArgs { Count = 0 }; using (SearchResultStream stream = await service.ExportSearchResultsAsync(search, args)) { } using (SearchResultStream stream = await service.ExportSearchResultsAsync(search, args)) { for (int i = 0; stream.ReadCount <= 0; i++) { await Task.Delay(10); } } await service.LogOffAsync(); } }
public async Task CanCancelExportSearchPreviews() { using (var service = await SdkHelper.CreateService()) { const string search = "search index=_internal | tail 1000 | stats count by method"; var args = new SearchExportArgs { Count = 0, EarliestTime = "-24h" }; using (SearchPreviewStream stream = await service.ExportSearchPreviewsAsync(search, args)) { } using (SearchPreviewStream stream = await service.ExportSearchPreviewsAsync(search, args)) { for (int i = 0; stream.ReadCount <= 0; i++) { await Task.Delay(10); } } await service.LogOffAsync(); } }
public Task<SearchResultStream> ExportSearchResultsAsync(string search, SearchExportArgs args = null) { Contract.Requires<ArgumentNullException>(search != null); return default(Task<SearchResultStream>); }
void CanSetEveryValue() { var args = new SearchExportArgs() { AutoCancel = 1, AutoFinalizeEventCount = 2, AutoPause = 3, Count = 10000, EarliestTime = "some_unchecked_string", EnableLookups = false, FieldList = new string[] { "some_unchecked_string", "some_other_unchecked_string" }, ForceBundleReplication = true, Id = "some_unchecked_string", IndexEarliest = "some_unchecked_string", IndexLatest = "some_unchecked_string", LatestTime = "some_unchecked_string", MaxLines = 4, MaxTime = 5, Namespace = "some_unchecked_string", Now = "some_unchecked_string", Offset = 6, OutputTimeFormat = "some_unchecked_string", ReduceFrequency = 9, RealTimeBlocking = true, RealTimeIndexFilter = true, RealTimeMaxBlockSeconds = 7, RealTimeQueueSize = 8, ReloadMacros = false, RemoteServerList = "server1,server2", RequiredFieldList = new string[] { "some_unchecked_string", "some_other_uncheck_string" }, Search = "some_unchecked_string", SearchListener = "some_unchecked_string", SearchMode = SearchMode.Realtime, Segmentation = "some_unchecked_string", SyncBundleReplication = true, TimeFormat = "some_unchecked_string", Timeout = 11, TruncationMode = TruncationMode.Truncate }; Assert.Equal(36, args.ToArray().Length); // includes two lists with two members each Assert.Equal( "auto_cancel=1; " + "auto_finalize_ec=2; " + "auto_pause=3; " + "count=10000; " + "earliest_time=some_unchecked_string; " + "enable_lookups=0; " + "f=some_unchecked_string; " + "f=some_other_unchecked_string; " + "force_bundle_replication=1; " + "id=some_unchecked_string; " + "index_earliest=some_unchecked_string; " + "index_latest=some_unchecked_string; " + "latest_time=some_unchecked_string; " + "max_lines=4; " + "max_time=5; " + "namespace=some_unchecked_string; " + "now=some_unchecked_string; " + "offset=6; " + "output_time_format=some_unchecked_string; " + "reduce_freq=9; " + "reload_macros=0; " + "remote_server_list=server1,server2; " + "rf=some_unchecked_string; " + "rf=some_other_uncheck_string; " + "rt_blocking=1; " + "rt_indexfilter=1; " + "rt_maxblocksecs=7; " + "rt_queue_size=8; " + "search=some_unchecked_string; " + "search_listener=some_unchecked_string; " + "search_mode=realtime; " + "segmentation=some_unchecked_string; " + "sync_bundle_replication=1; " + "time_format=some_unchecked_string; " + "timeout=11; " + "truncation_mode=truncate", args.ToString()); Assert.Equal(new Argument[] { new Argument("auto_cancel", "1"), new Argument("auto_finalize_ec", "2"), new Argument("auto_pause", "3"), new Argument("count", "10000"), new Argument("earliest_time", "some_unchecked_string"), new Argument("enable_lookups", 0), new Argument("f", "some_unchecked_string"), new Argument("f", "some_other_unchecked_string"), new Argument("force_bundle_replication", 1), new Argument("id", "some_unchecked_string"), new Argument("index_earliest", "some_unchecked_string"), new Argument("index_latest", "some_unchecked_string"), new Argument("latest_time", "some_unchecked_string"), new Argument("max_lines", "4"), new Argument("max_time", "5"), new Argument("namespace", "some_unchecked_string"), new Argument("now", "some_unchecked_string"), new Argument("offset", "6"), new Argument("output_time_format", "some_unchecked_string"), new Argument("reduce_freq", "9"), new Argument("reload_macros", "0"), new Argument("remote_server_list", "server1,server2"), new Argument("rf", "some_unchecked_string"), new Argument("rf", "some_other_uncheck_string"), new Argument("rt_blocking", 1), new Argument("rt_indexfilter", 1), new Argument("rt_maxblocksecs", "7"), new Argument("rt_queue_size", "8"), new Argument("search", "some_unchecked_string"), new Argument("search_listener", "some_unchecked_string"), new Argument("search_mode", "realtime"), new Argument("segmentation", "some_unchecked_string"), new Argument("sync_bundle_replication", 1), new Argument("time_format", "some_unchecked_string"), new Argument("timeout", "11"), new Argument("truncation_mode", "truncate") }, args.ToArray()); }