Skip to content

Commit 2485f1b

Browse files
committed
Rolling benchmark report indexes by month.
1 parent 1569bf2 commit 2485f1b

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

build/scripts/Benchmarking.fsx

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Benchmarker =
2727

2828
let pipelineName = "benchmark-pipeline"
2929
let indexName = IndexName.op_Implicit("benchmark-reports")
30-
let typeName = TypeName.op_Implicit("report")
30+
let typeName = TypeName.op_Implicit("benchmarkreport")
3131

3232
type Memory(gen0Collections:int, gen1Collections: int, gen2Collections: int, totalOperations:int64, bytesAllocatedPerOperation:int64) =
3333
member val Gen0Collections=gen0Collections with get, set
@@ -111,7 +111,7 @@ module Benchmarker =
111111
member val Statistics=statistics with get, set
112112
member val Memory=memory with get, set
113113

114-
type Report(title: string, totalTime:TimeSpan, date:DateTime, commit:string, host:HostEnvironmentInfo, benchmarks:Benchmark list) =
114+
type BenchmarkReport(title: string, totalTime:TimeSpan, date:DateTime, commit:string, host:HostEnvironmentInfo, benchmarks:Benchmark list) =
115115
member val Title = title with get, set
116116
member val TotalTime = totalTime with get, set
117117
member val Date = date with get, set
@@ -152,13 +152,13 @@ module Benchmarker =
152152

153153
let IndexResult (client:ElasticClient, file:string, date:DateTime, commit:string, indexName, typeName) =
154154

155-
trace ("Indexing report " + file + " into Elasticsearch")
155+
trace (sprintf "Indexing report %s into Elasticsearch" file)
156156

157-
let document = JsonConvert.DeserializeObject<Report>(File.ReadAllText(file))
157+
let document = JsonConvert.DeserializeObject<BenchmarkReport>(File.ReadAllText(file))
158158
document.Date <- date
159159
document.Commit <- commit
160160

161-
let indexRequest = new IndexRequest<Report>(indexName, typeName)
161+
let indexRequest = new IndexRequest<BenchmarkReport>(indexName, typeName)
162162
indexRequest.Document <- document
163163
indexRequest.Pipeline <- pipelineName
164164

@@ -169,7 +169,7 @@ module Benchmarker =
169169

170170
let IndexResults (url, username, password) =
171171
if (String.IsNullOrEmpty url = false) then
172-
trace "Indexing benchmark results into Elasticsearch"
172+
trace "Indexing benchmark reports into Elasticsearch"
173173

174174
let date = DateTime.UtcNow
175175
let commit = getSHA1 "." "HEAD"
@@ -185,26 +185,35 @@ module Benchmarker =
185185
connectionSettings.BasicAuthentication(username, password) |> ignore
186186

187187
let client = new ElasticClient(connectionSettings)
188-
189-
let indexExists = client.IndexExists(Indices.op_Implicit(indexName)).Exists
190-
191-
if indexExists = false then
192-
let createIndex = client.CreateIndex(indexName, fun c ->
193-
c.Mappings(fun m ->
194-
m.Map<Report>(fun mm ->
195-
mm.AutoMap()
196-
.Properties(fun p ->
197-
p.Nested<Benchmark>(fun n ->
198-
n.AutoMap().Name(PropertyName.op_Implicit("benchmarks")) :> INestedProperty
199-
) :> IPromise<IProperties>
200-
) :> ITypeMapping
201-
) :> IPromise<IMappings>
202-
) :> ICreateIndexRequest
203-
)
204-
205-
if createIndex.IsValid = false then
206-
raise (Exception("Unable to create index into Elasticsearch"))
207-
188+
189+
let indexTemplateExists = client.IndexTemplateExists(Name.op_Implicit("benchmarks")).Exists
190+
191+
if indexTemplateExists |> not then
192+
193+
let typeMapping = new TypeMappingDescriptor<BenchmarkReport>()
194+
typeMapping.AutoMap() |> ignore
195+
typeMapping.Properties(fun p ->
196+
p.Nested<Benchmark>(fun n ->
197+
n.AutoMap().Name(PropertyName.op_Implicit("benchmarks")) :> INestedProperty
198+
) :> IPromise<IProperties>
199+
) |> ignore
200+
201+
let mappings = new Mappings()
202+
mappings.Add(typeName, typeMapping :> ITypeMapping)
203+
204+
let indexSettings = new IndexSettings()
205+
indexSettings.NumberOfShards <- Nullable 1
206+
207+
let putIndexTemplateRequest = new PutIndexTemplateRequest(Name.op_Implicit("benchmarks"))
208+
putIndexTemplateRequest.Template <- "benchmark-reports-*"
209+
putIndexTemplateRequest.Mappings <- mappings
210+
putIndexTemplateRequest.Settings <- indexSettings
211+
212+
let putIndexTemplateResponse = client.PutIndexTemplate(putIndexTemplateRequest)
213+
214+
if putIndexTemplateResponse.IsValid = false then
215+
raise (Exception("Unable to create index template into Elasticsearch"))
216+
208217
let processor = new GrokProcessor();
209218
processor.Field <- new Field("_ingest._value.displayInfo")
210219
processor.Patterns <- ["%{WORD:_ingest._value.class}.%{DATA:_ingest._value.method}: Job-%{WORD:_ingest._value.jobName}\\(Jit=%{WORD:_ingest._value.jit}, Runtime=%{WORD:_ingest._value.clr}, LaunchCount=%{NUMBER:_ingest._value.launchCount}, RunStrategy=%{WORD:_ingest._value.runStrategy}, TargetCount=%{NUMBER:_ingest._value.targetCount}, UnrollFactor=%{NUMBER:_ingest._value.unrollFactor}, WarmupCount=%{NUMBER:_ingest._value.warmupCount}\\)"]
@@ -213,15 +222,22 @@ module Benchmarker =
213222
forEachProcessor.Field <- new Field("benchmarks")
214223
forEachProcessor.Processor <- processor
215224

225+
let dateIndexProcessor = new DateIndexNameProcessor();
226+
dateIndexProcessor.Field <- new Field("date")
227+
dateIndexProcessor.IndexNamePrefix <- "benchmark-reports-"
228+
dateIndexProcessor.DateRounding <- DateRounding.Month
229+
dateIndexProcessor.DateFormats <- ["yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ"]
230+
216231
let request = new PutPipelineRequest(Id.op_Implicit(pipelineName))
217-
request.Description <- "Grok benchmark settings"
218-
request.Processors <- [forEachProcessor]
232+
request.Description <- "Benchmark settings pipeline"
233+
request.Processors <- [dateIndexProcessor; forEachProcessor]
219234

220235
let createPipeline = client.PutPipeline(request)
221236

222237
if createPipeline.IsValid = false then
223238
raise (Exception("Unable to create pipeline"))
224239

225-
for file in benchmarkJsonFiles do IndexResult (client, file, date, commit, indexName, typeName)
240+
for file in benchmarkJsonFiles
241+
do IndexResult (client, file, date, commit, indexName, typeName)
226242

227-
trace "Indexed benchmark results into Elasticsearch"
243+
trace "Indexed benchmark reports into Elasticsearch"

0 commit comments

Comments
 (0)