/
MainSummaryView.scala
1345 lines (1189 loc) · 68.3 KB
/
MainSummaryView.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package com.mozilla.telemetry.views
import java.time._
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import com.mozilla.telemetry.ndjson.Dataset
import com.mozilla.telemetry.metrics._
import com.mozilla.telemetry.utils._
import org.apache.spark.SparkContext
import org.apache.spark.sql.{Row, SparkSession}
import org.apache.spark.sql.types._
import org.json4s.JsonAST._
import org.json4s.{DefaultFormats, JValue}
import org.rogach.scallop._
import scala.util.{Success, Try}
object MainSummaryView extends BatchJobBase {
private val logger = org.apache.log4j.Logger.getLogger(this.getClass.getName)
def schemaVersion: String = "v4"
def jobName: String = "main_summary"
// Allow at most .005% of records to be ignored
// Records are ignored when we can't properly deserialize them
val MaxFractionIgnoredPings = .00005
// The following user prefs will be included as top-level
// fields, named according to UserPref.fieldName()
//
// Prefs where we only record whether a pref has been set should
// use StringUserPref as we observe a value of "<user-set>".
//
// Supported pref data types are:
// nsIPrefBranch.PREF_STRING -> StringUserPref
// nsIPrefBranch.PREF_BOOL -> BooleanUserPref
// nsIPrefBranch.PREF_INT -> IntegerUserPref
// See the `_getPrefData()` function in TelemetryEnvironment.jsm
// for reference: https://mzl.la/2zo7kyK
val userPrefsList =
BooleanUserPref("browser.launcherProcess.enabled") ::
BooleanUserPref("browser.search.widget.inNavBar") ::
StringUserPref("browser.search.region") ::
BooleanUserPref("extensions.allow-non-mpc-extensions") ::
BooleanUserPref("extensions.legacy.enabled") ::
BooleanUserPref("gfx.webrender.all.qualified") ::
BooleanUserPref("marionette.enabled") ::
BooleanUserPref("privacy.fuzzyfox.enabled") ::
IntegerUserPref("dom.ipc.plugins.sandbox-level.flash") ::
IntegerUserPref("dom.ipc.processCount") ::
StringUserPref("general.config.filename") ::
BooleanUserPref("security.enterprise_roots.auto-enabled") ::
BooleanUserPref("security.enterprise_roots.enabled") ::
BooleanUserPref("security.pki.mitm_detected") :: Nil
val allowedHistograms =
"A11Y_CONSUMERS" ::
"A11Y_INSTANTIATED_FLAG" ::
"CERT_VALIDATION_SUCCESS_BY_CA" ::
"CHECKERBOARD_SEVERITY" ::
"COMPOSITE_TIME" ::
"CONTENT_FRAME_TIME" ::
"CONTENT_PAINT_TIME" ::
"COOKIE_BEHAVIOR" ::
"CYCLE_COLLECTOR_MAX_PAUSE" ::
"DEVTOOLS_ABOUTDEBUGGING_OPENED_COUNT" ::
"DEVTOOLS_ABOUT_DEVTOOLS_OPENED_KEY" ::
"DEVTOOLS_ABOUT_DEVTOOLS_OPENED_REASON" ::
"DEVTOOLS_ACCESSIBILITY_PICKER_TIME_ACTIVE_SECONDS" ::
"DEVTOOLS_ACCESSIBILITY_SERVICE_TIME_ACTIVE_SECONDS" ::
"DEVTOOLS_ACCESSIBILITY_TIME_ACTIVE_SECONDS" ::
"DEVTOOLS_ANIMATIONINSPECTOR_OPENED_COUNT" ::
"DEVTOOLS_BROWSERCONSOLE_OPENED_COUNT" ::
"DEVTOOLS_CANVASDEBUGGER_OPENED_COUNT" ::
"DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT" ::
"DEVTOOLS_CUSTOM_OPENED_COUNT" ::
"DEVTOOLS_DOM_OPENED_COUNT" ::
"DEVTOOLS_ENTRY_POINT" ::
"DEVTOOLS_EYEDROPPER_OPENED_COUNT" ::
"DEVTOOLS_FONTEDITOR_FONT_TYPE_DISPLAYED" ::
"DEVTOOLS_FONTEDITOR_N_FONTS_RENDERED" ::
"DEVTOOLS_FONTEDITOR_N_FONT_AXES" ::
"DEVTOOLS_FONTINSPECTOR_OPENED_COUNT" ::
"DEVTOOLS_INSPECTOR_OPENED_COUNT" ::
"DEVTOOLS_JSBROWSERDEBUGGER_OPENED_COUNT" ::
"DEVTOOLS_JSDEBUGGER_OPENED_COUNT" ::
"DEVTOOLS_JSPROFILER_OPENED_COUNT" ::
"DEVTOOLS_LAYOUTVIEW_OPENED_COUNT" ::
"DEVTOOLS_MEMORY_OPENED_COUNT" ::
"DEVTOOLS_MENU_EYEDROPPER_OPENED_COUNT" ::
"DEVTOOLS_NETMONITOR_OPENED_COUNT" ::
"DEVTOOLS_OPTIONS_OPENED_COUNT" ::
"DEVTOOLS_PAINTFLASHING_OPENED_COUNT" ::
"DEVTOOLS_PICKER_EYEDROPPER_OPENED_COUNT" ::
"DEVTOOLS_RESPONSIVE_OPENED_COUNT" ::
"DEVTOOLS_RULEVIEW_OPENED_COUNT" ::
"DEVTOOLS_SCRATCHPAD_OPENED_COUNT" ::
"DEVTOOLS_SCRATCHPAD_WINDOW_OPENED_COUNT" ::
"DEVTOOLS_SHADEREDITOR_OPENED_COUNT" ::
"DEVTOOLS_STORAGE_OPENED_COUNT" ::
"DEVTOOLS_STYLEEDITOR_OPENED_COUNT" ::
"DEVTOOLS_TOOLBOX_TIME_ACTIVE_SECONDS" ::
"DEVTOOLS_WEBAUDIOEDITOR_OPENED_COUNT" ::
"DEVTOOLS_WEBCONSOLE_OPENED_COUNT" ::
"DEVTOOLS_WEBIDE_OPENED_COUNT" ::
"DNS_FAILED_LOOKUP_TIME" ::
"DNS_LOOKUP_TIME" ::
"FX_NEW_WINDOW_MS" ::
"FX_PAGE_LOAD_MS_2" ::
"FX_SEARCHBAR_SELECTED_RESULT_METHOD" ::
"FX_SESSION_RESTORE_RESTORE_WINDOW_MS" ::
"FX_SESSION_RESTORE_STARTUP_INIT_SESSION_MS" ::
"FX_SESSION_RESTORE_STARTUP_ONLOAD_INITIAL_WINDOW_MS" ::
"FX_TAB_CLOSE_TIME_ANIM_MS" ::
"FX_TAB_SWITCH_TOTAL_E10S_MS" ::
"FX_TAB_SWITCH_UPDATE_MS" ::
"FX_URLBAR_SELECTED_RESULT_INDEX" ::
"FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE" ::
"FX_URLBAR_SELECTED_RESULT_METHOD" ::
"FX_URLBAR_SELECTED_RESULT_TYPE" ::
"GC_ANIMATION_MS" ::
"GC_MAX_PAUSE_MS_2" ::
"GEOLOCATION_REQUEST_GRANTED" ::
"GHOST_WINDOWS" ::
"GPU_PROCESS_INITIALIZATION_TIME_MS" ::
"GPU_PROCESS_LAUNCH_TIME_MS_2" ::
"HTTP_CHANNEL_DISPOSITION" ::
"HTTP_PAGELOAD_IS_SSL" ::
"HTTP_TRANSACTION_IS_SSL" ::
"INPUT_EVENT_RESPONSE_COALESCED_MS" ::
"IPC_READ_MAIN_THREAD_LATENCY_MS" ::
"MEMORY_DISTRIBUTION_AMONG_CONTENT" ::
"MEMORY_HEAP_ALLOCATED" ::
"MEMORY_RESIDENT_FAST" ::
"MEMORY_TOTAL" ::
"MEMORY_UNIQUE" ::
"MEMORY_UNIQUE_CONTENT_STARTUP" ::
"MEMORY_VSIZE" ::
"MEMORY_VSIZE_MAX_CONTIGUOUS" ::
"NETWORK_CACHE_METADATA_FIRST_READ_TIME_MS" ::
"NETWORK_CACHE_V2_HIT_TIME_MS" ::
"NETWORK_CACHE_V2_MISS_TIME_MS" ::
"NUMBER_OF_PROFILES" ::
"PLACES_AUTOCOMPLETE_6_FIRST_RESULTS_TIME_MS" ::
"PLUGIN_SHUTDOWN_MS" ::
"PWMGR_BLOCKLIST_NUM_SITES" ::
"PWMGR_FORM_AUTOFILL_RESULT" ::
"PWMGR_LOGIN_LAST_USED_DAYS" ::
"PWMGR_LOGIN_PAGE_SAFETY" ::
"PWMGR_MANAGE_COPIED_PASSWORD" ::
"PWMGR_MANAGE_COPIED_USERNAME" ::
"PWMGR_MANAGE_DELETED" ::
"PWMGR_MANAGE_OPENED" ::
"PWMGR_MANAGE_VISIBILITY_TOGGLED" ::
"PWMGR_NUM_PASSWORDS_PER_HOSTNAME" ::
"PWMGR_NUM_SAVED_PASSWORDS" ::
"PWMGR_PROMPT_REMEMBER_ACTION" ::
"PWMGR_PROMPT_UPDATE_ACTION" ::
"PWMGR_SAVING_ENABLED" ::
"SANDBOX_REJECTED_SYSCALLS" ::
"SEARCH_SERVICE_INIT_MS" ::
"SSL_HANDSHAKE_RESULT" ::
"SSL_HANDSHAKE_VERSION" ::
"SSL_TLS12_INTOLERANCE_REASON_PRE" ::
"SSL_TLS13_INTOLERANCE_REASON_PRE" ::
"TIME_TO_DOM_COMPLETE_MS" ::
"TIME_TO_DOM_CONTENT_LOADED_END_MS" ::
"TIME_TO_DOM_CONTENT_LOADED_START_MS" ::
"TIME_TO_DOM_INTERACTIVE_MS" ::
"TIME_TO_DOM_LOADING_MS" ::
"TIME_TO_FIRST_CLICK_MS" ::
"TIME_TO_FIRST_INTERACTION_MS" ::
"TIME_TO_FIRST_KEY_INPUT_MS" ::
"TIME_TO_FIRST_MOUSE_MOVE_MS" ::
"TIME_TO_FIRST_SCROLL_MS" ::
"TIME_TO_LOAD_EVENT_END_MS" ::
"TIME_TO_LOAD_EVENT_START_MS" ::
"TIME_TO_NON_BLANK_PAINT_MS" ::
"TIME_TO_RESPONSE_START_MS" ::
"TOUCH_ENABLED_DEVICE" ::
"TRACKING_PROTECTION_ENABLED" ::
// Bug 1552213; UPDATE histograms can likely be removed after FF 69 or 70.
"UPDATE_CAN_USE_BITS_NOTIFY" ::
"UPDATE_DOWNLOAD_CODE_PARTIAL" ::
"UPDATE_DOWNLOAD_CODE_COMPLETE" ::
"UPDATE_BITS_RESULT_PARTIAL" ::
"UPDATE_BITS_RESULT_COMPLETE" ::
"UPDATE_STATE_CODE_PARTIAL_STAGE" ::
"UPDATE_STATE_CODE_COMPLETE_STAGE" ::
"UPDATE_STATUS_ERROR_CODE_COMPLETE_STAGE" ::
"UPDATE_STATUS_ERROR_CODE_PARTIAL_STAGE" ::
"UPDATE_STATE_CODE_PARTIAL_STARTUP" ::
"UPDATE_STATE_CODE_COMPLETE_STARTUP" ::
"UPDATE_STATUS_ERROR_CODE_PARTIAL_STARTUP" ::
"UPDATE_STATUS_ERROR_CODE_COMPLETE_STARTUP" ::
"UPTAKE_REMOTE_CONTENT_RESULT_1" ::
"WEBEXT_BACKGROUND_PAGE_LOAD_MS" ::
"WEBEXT_BROWSERACTION_POPUP_OPEN_MS" ::
"WEBEXT_BROWSERACTION_POPUP_PRELOAD_RESULT_COUNT" ::
"WEBEXT_CONTENT_SCRIPT_INJECTION_MS" ::
"WEBEXT_EXTENSION_STARTUP_MS" ::
"WEBEXT_PAGEACTION_POPUP_OPEN_MS" ::
"WEBEXT_STORAGE_LOCAL_GET_MS" ::
"WEBEXT_STORAGE_LOCAL_SET_MS" ::
"WEBVR_TIME_SPENT_VIEWING_IN_2D" ::
"WEBVR_TIME_SPENT_VIEWING_IN_OCULUS" ::
"WEBVR_TIME_SPENT_VIEWING_IN_OPENVR" ::
"WEBVR_USERS_VIEW_IN" :: Nil
/**
* Count and Flag histograms are both automatically
* transformed into Scalars. Count histograms become
* integer counts, and Flag histograms become boolean
* values.
*
* If instead a count or flag histogram should have
* it's natural histogram representation - a Map
* of buckets and their associated counts - then
* including the probe name here will ensure that.
*
* For example, a Flag histogram with values
* {0: 1, 1: 0} will be recorded as False. However,
* including the probe name here will store the
* {0: 1, 1: 0} Map instead.
*
* WARNING: Removing or adding to this list will change
* the schema for that probe's columns, rendering all
* previous data unreadable. The normal method is to
* include a probe name here when added to the allowed list,
* and never remove it.
*/
val NaturalHistogramRepresentationList =
"A11Y_INSTANTIATED_FLAG" :: Nil
/*
* Addon scalars are included as a key, value
* in a MAP type column. For example, the boolean
* and keyed scalarType becomes a column with name
* keyed_boolean_addon_scalars and type
* Map[String, Map[String, boolean]];
* where top-level keys are probe names.
**/
val addonScalarSchema =
BooleanScalarType() ::
BooleanScalarType(keyed = true) ::
StringScalarType() ::
StringScalarType(keyed = true) ::
UintScalarType() ::
UintScalarType(keyed = true) :: Nil
// Configuration for command line arguments
private class Conf(args: Array[String]) extends BaseOpts(args) {
val limit = opt[Int]("limit", descr = "Per-date maximum number of: files to read for --input-source=heka or rows to read for --input-source=ndjson",
required = false)
val channel = opt[String]("channel", descr = "Only process data from the given channel", required = false)
val appVersion = opt[String]("version", descr = "Only process data from the given app version", required = false)
val allHistograms = opt[Boolean]("all-histograms", descr = "Flag to use all histograms", required = false)
val docType = opt[String]("doc-type", descr = "DocType of pings conforming to main ping schema", required=false, default=Some("main"))
// 500,000 rows yields ~ 200MB files in snappy+parquet
val maxRecordsPerFile = opt[Int]("max-records-per-file", descr = "Max number of rows to write to output files before splitting",
required = false, default=Some(500000))
val readMode = choice(Seq("fixed", "aligned"), name="read-mode", descr="Read fixed-sized partitions or a multiple of defaultParallelism partitions",
default=Some("fixed"))
val inputPartitionMultiplier = opt[Int]("input-partition-multiplier", descr="Partition multiplier for aligned read-mode", default=Some(4))
val schemaReportLocation = opt[String]("schema-report-location", descr="Write schema.treeString to this file")
val inputSource = choice(Seq("heka", "ndjson"), name="input-source",
descr="Read raw pings from heka protobuf in S3 (heka) or newline delimited json in Google Cloud Storage (ndjson)", default=Some("heka"))
val inputBucket = opt[String]("input-bucket", descr="Bucket override for --input-source=ndjson", default=Some(Dataset.BUCKET))
val disableStopContextAtEnd = opt[Boolean]("disable-stop-context-at-end", descr = "Flag to leave spark context running", required = false)
verify()
}
def main(args: Array[String]) {
val conf = new Conf(args) // parse command line arguments
// add s3 filesystem to outputBucket if none is specified for backward compatibility
val Pattern = "(.*://.*)".r
val outputBucket = conf.outputBucket() match {
case Pattern(bucket) => bucket
case bucket => s"s3://$bucket"
}
try{
// Set up Spark
for (submissionDate <- datesBetween(conf.from(), conf.to.toOption)) {
implicit val spark: SparkSession = getOrCreateSparkSession(jobName)
implicit val sc: SparkContext = spark.sparkContext
val sqlContext = spark.sqlContext
val hadoopConf = sc.hadoopConfiguration
hadoopConf.set("fs.s3n.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
// prevent hadoop from trying to repair implicit directories on potentially read-only gs:// locations
spark.conf.set("fs.gs.implicit.dir.repair.enable", false)
val filterChannel = conf.channel.get
val filterVersion = conf.appVersion.get
val filterDocType = conf.docType()
logger.info("=======================================================================================")
logger.info(s"BEGINNING JOB $jobName FOR $submissionDate")
logger.info(s" Filtering for docType = '${filterDocType}'")
if (filterChannel.nonEmpty) logger.info(s" Filtering for channel = '${filterChannel.get}'")
if (filterVersion.nonEmpty) logger.info(s" Filtering for version = '${filterVersion.get}'")
val scalarDefinitions = Scalars.definitions(includeOptin = true)
.toList.sortBy(_._1)
.filter(!_._2.originalName.startsWith("telemetry.mock"))
val histogramDefinitions = filterHistogramDefinitions(
Histograms.definitions(includeOptin = true, nameJoiner = Histograms.prefixProcessJoiner _, includeCategorical = true),
useAllowlist = !conf.allHistograms())
val schema = buildSchema(userPrefsList, scalarDefinitions, histogramDefinitions)
val ignoredCount = sc.accumulator(0, "Number of Records Ignored")
val processedCount = sc.accumulator(0, "Number of Records Processed")
val telemetrySource = submissionDate match {
case d if d < "20161012" => "telemetry-oldinfra"
case _ => "telemetry"
}
// if `fixed`, then data is read in fixed 268MB blocks
val numPartitions = conf.readMode() match {
case "aligned" => Some(sc.defaultParallelism * conf.inputPartitionMultiplier())
case _ => None
}
val ds = Dataset(
telemetrySource,
Some(submissionDate),
conf.inputBucket(),
Map[String, PartialFunction[String, Boolean]](
"document_namespace" -> { case "telemetry" => true},
"document_version" -> { case "4" => true },
"document_type" -> { case dt if dt == filterDocType => true },
"normalized_app_name" -> { case "Firefox" => true }
) ++ filterChannel.map(
expect => ("normalized_channel", { case channel if channel == expect => true }: PartialFunction[String, Boolean])
) ++ filterVersion.map(
expect => ("app_version", { case v if v == expect => true }: PartialFunction[String, Boolean])
)
)
val messages = conf.inputSource() match {
case "ndjson" => ds.records(conf.limit.toOption)
case "heka" => ds.asHeka.records(conf.limit.toOption, numPartitions).map(_.toJValue)
}
// Note we cannot just use 'partitionBy' below to automatically populate
// the submission_date partition, because none of the write modes do
// quite what we want:
// - "overwrite" causes the entire vX partition to be deleted and replaced with
// the current day's data, so doesn't work with incremental jobs
// - "append" would allow us to generate duplicate data for the same day, so
// we would need to add some manual checks before running
// - "error" (the default) causes the job to fail after any data is
// loaded, so we can't do single day incremental updates.
// - "ignore" causes new data not to be saved.
// So we manually add the "submission_date" parameter to the outputPath.
val keyPrefix = s"${filterDocType}_summary/$schemaVersion/submission_date_s3=$submissionDate"
val outputPath = s"$outputBucket/$keyPrefix"
if(!messages.isEmpty()){
val rowRDD = messages.flatMap(m => {
val row = m.map(doc => messageToRow(doc, scalarDefinitions, histogramDefinitions))
row match {
case None =>
ignoredCount += 1
None
case Some(x) =>
processedCount += 1
x
}
})
val records = sqlContext.createDataFrame(rowRDD, schema)
// Repartition the dataframe by sample_id before saving.
val partitioned = records.repartition(100, records.col("sample_id"))
// limit the size of output files so they don't break during upload
val maxRecordsPerFile = conf.maxRecordsPerFile()
// Then write using the given fields as path name partitions. Overwrites existing data.
partitioned.write.partitionBy("sample_id").mode("overwrite").option("maxRecordsPerFile", maxRecordsPerFile).parquet(outputPath)
conf.schemaReportLocation.get match {
case Some(path) => writeTextFile(path, partitioned.schema.treeString)
case None =>
}
}
val recordsIgnored = ignoredCount.value
val recordsSeen = recordsIgnored + processedCount.value
logger.info(s"JOB $jobName COMPLETED SUCCESSFULLY FOR $submissionDate")
logger.info(" RECORDS SEEN: %d".format(recordsSeen))
logger.info(" RECORDS IGNORED: %d".format(recordsIgnored))
logger.info("=======================================================================================")
if ((1.0 * recordsIgnored) / recordsSeen > MaxFractionIgnoredPings) {
throw TooManyRecordsIgnoredException(
s"More records ignored than are allowed. Ignored $recordsIgnored out of $recordsSeen records.",
conf.outputBucket(), keyPrefix)
}
if (shouldStopContextAtEnd(spark) && !conf.disableStopContextAtEnd()) { spark.stop() }
}
} catch {
// Delete incomplete data
case e@TooManyRecordsIgnoredException(_, bucket, prefix) =>
deletePrefix(bucket, prefix)
throw e
}
}
def getActiveAddons(activeAddons: JValue): Option[List[Row]] = {
implicit val formats = DefaultFormats
Try(activeAddons.extract[Map[String, Addon]]) match {
case Success(addons) => {
val rows = addons.map { case (addonId, addonData) =>
Row(addonId,
addonData.blocklisted.orNull,
addonData.name.orNull,
addonData.userDisabled.orNull,
addonData.appDisabled.orNull,
addonData.version.orNull,
addonData.scope.orNull,
addonData.`type`.orNull,
addonData.foreignInstall.orNull,
addonData.hasBinaryComponents.orNull,
addonData.installDay.orNull,
addonData.updateDay.orNull,
addonData.signedState.orNull,
addonData.isSystem.orNull,
addonData.isWebExtension.orNull,
addonData.multiprocessCompatible.orNull)
}
Some(rows.toList)
}
case _ => None
}
}
def getDisabledAddons(activeAddons: JValue, addonDetails: JValue): Option[List[String]] = {
// Get the list of ids from the active addons.
val activeIds = activeAddons match {
case JObject(addons) => addons.map(k => k._1)
case _ => List()
}
// Only report the ids of the addons which are in the addonDetails but not in the activeAddons.
// They are the disabled addons (possibly because they are legacy). We need this as addonDetails
// may contain both disabled and active addons.
addonDetails match {
case JObject(addons) => Some(addons.map(k => k._1).filter(k => !activeIds.contains(k)))
case _ => None
}
}
def getTheme(theme: JValue): Option[Row] = {
implicit val formats = DefaultFormats
Try(theme.extract[Addon]) match {
case Success(addonData) =>
Some(Row(addonData.id.getOrElse("MISSING"),
addonData.blocklisted.orNull,
addonData.name.orNull,
addonData.userDisabled.orNull,
addonData.appDisabled.orNull,
addonData.version.orNull,
addonData.scope.orNull,
addonData.`type`.orNull,
addonData.foreignInstall.orNull,
addonData.hasBinaryComponents.orNull,
addonData.installDay.orNull,
addonData.updateDay.orNull,
addonData.signedState.orNull,
addonData.isSystem.orNull,
addonData.isWebExtension.orNull,
addonData.multiprocessCompatible.orNull))
case _ => None
}
}
def getQuantumReady(e10sStatus: JValue, addons: JValue, theme: JValue): Option[Boolean] = {
val e10sEnabled = e10sStatus match {
case JBool(x) => Some(x)
case _ => None
}
val allowedAddons = getActiveAddons(addons) match {
case Some(l) if l.nonEmpty => Some(
l.map(row => {
val isSystem = row.get(13) match {
case b: Boolean => b
case _ => false
}
val isWebExtension = row.get(14) match {
case b: Boolean => b
case _ => false
}
isSystem || isWebExtension
}).reduce(_ && _))
case Some(l) => Some(true) // no addons => quantumReady = true
case _ => None
}
val requiredThemes = List(
"{972ce4c6-7e08-4474-a285-3208198ce6fd}",
"firefox-compact-light@mozilla.org",
"firefox-compact-dark@mozilla.org"
)
val allowedTheme = getTheme(theme) match {
case Some(t) => t.get(0) match {
case id: String => id match {
case "MISSING" => None
case other => Some(requiredThemes.contains(id))
}
case _ => None
}
case _ => None
}
for {
e10s <- e10sEnabled
theme <- allowedTheme
addons <- allowedAddons
} yield (e10s && theme && addons)
}
def getAttribution(attribution: JValue): Option[Row] = {
// Return value mirrors the case class Attribution. If all the columns
// are null, then then whole attribution field is null.
implicit val formats = DefaultFormats
Try(attribution.extract[Attribution]) match {
case Success(attributionData) =>
val row = Row(
attributionData.source.orNull,
attributionData.medium.orNull,
attributionData.campaign.orNull,
attributionData.content.orNull)
row match {
case Row(null, null, null, null) => None
case attrib => Some(attrib)
}
case _ => None
}
}
@deprecated
def getOldUserPrefs(prefs: JValue): Option[Row] = {
val pc = prefs \ "dom.ipc.processCount" match {
case JInt(x) => x.toInt
case _ => null
}
val anme = prefs \ "extensions.allow-non-mpc-extensions" match {
case JBool(x) => x
case _ => null
}
val row = Row(pc, anme)
row match {
case Row(null, null) => None
case nonempty => Some(nonempty)
}
}
def getUserPrefs(prefs: JValue, prefsList: List[UserPref]): Row = {
val prefValues = prefsList.map(p => p.getValue(prefs \ p.name))
Row.fromSeq(prefValues)
}
def getExperiments(jExperiments: JValue): Option[Map[String, String]] = {
implicit val formats = DefaultFormats
Try(jExperiments.extract[Map[String, Experiment]]) match {
case Success(experiments) => {
if (experiments.nonEmpty) {
Some(experiments.map { case (id, data) => id -> data.branch.orNull })
} else {
None
}
}
case _ => None
}
}
def diffDateAndTimestamp(dateString: String, dateFormat: DateTimeFormatter, timestamp: Long): Option[Long] = {
val diff = for {
client <- Try(ZonedDateTime.parse(dateString, dateFormat))
server <- Try(ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp / 1e9.toLong), ZoneOffset.UTC))
} yield ChronoUnit.SECONDS.between(client, server)
diff match {
case Success(d) => Some(d)
case _ => None
}
}
// Parse clientDateHeader as a RFC1123 date, compute the difference between
// that and `timestamp` (in nanos), return the difference in seconds.
def getClockSkew(clientDateHeader: Option[String], timestamp: Long): Option[Long] = {
clientDateHeader match {
case Some(s) => diffDateAndTimestamp(s, DateTimeFormatter.RFC_1123_DATE_TIME, timestamp)
case _ => None
}
}
// Parse creationDate field as an ISO date, compute the difference between
// that and `timestamp` (in nanos), return the difference in seconds.
def getSubmissionLatency(clientCreationDate: Option[String], timestamp: Long): Option[Long] = {
clientCreationDate match {
case Some(s) => diffDateAndTimestamp(s, DateTimeFormatter.ISO_DATE_TIME, timestamp)
case _ => None
}
}
// Convert the given Heka message containing a "main" ping
// to a map containing just the fields we're interested in.
def messageToRow(doc: JValue,
scalarDefinitions: List[(String, ScalarDefinition)],
histogramDefinitions: List[(String, HistogramDefinition)],
naturalHistogramRepresentationList: List[String] = NaturalHistogramRepresentationList,
userPrefs: List[UserPref] = userPrefsList
): Option[Row] = {
try {
implicit val formats = DefaultFormats
val environment = doc \ "environment"
val payload = doc \ "payload"
val meta = doc \ "meta"
// required fields
val documentId = (meta \ "documentId").extractOpt[String]
val submissionDate = (meta \ "submissionDate").extractOpt[String]
val timestamp = (meta \ "Timestamp").extractOpt[Long]
if (documentId.isEmpty || submissionDate.isEmpty || timestamp.isEmpty) {
//scalastyle:off return
return None
//scalastyle:on return
}
val addons = environment \ "addons"
val addonDetails = payload \ "addonDetails"
val application = doc \ "application"
val build = environment \ "build"
val experiments = environment \ "experiments"
val profile = environment \ "profile"
val partner = environment \ "partner"
val settings = environment \ "settings"
val system = environment \ "system"
val info = payload \ "info"
val simpleMeasures = payload \ "simpleMeasurements"
val histograms = MainPing.DefaultProcessTypes.map {
case "parent" => "parent" -> payload \ "histograms"
case p => p -> payload \ "processes" \ p \ "histograms"
}.toMap
val keyedHistograms = MainPing.DefaultProcessTypes.map {
case "parent" => "parent" -> payload \ "keyedHistograms"
case p => p -> payload \ "processes" \ p \ "keyedHistograms"
}.toMap
val scalars = MainPing.DefaultProcessTypes.map {
p => p -> payload \ "processes" \ p \ "scalars"
}.toMap
val keyedScalars = MainPing.DefaultProcessTypes.map {
p => p -> payload \ "processes" \ p \ "keyedScalars"
}.toMap
val addonScalars = payload \ "processes" \ MainPing.DynamicProcess \ "scalars"
val addonKeyedScalars = payload \ "processes" \ MainPing.DynamicProcess \ "keyedScalars"
val fxaConfigured = MainPing.booleanHistogramToBoolean(histograms("parent") \ "FXA_CONFIGURED")
val weaveConfigured = MainPing.booleanHistogramToBoolean(histograms("parent") \ "WEAVE_CONFIGURED")
val weaveDesktop = MainPing.enumHistogramToCount(histograms("parent") \ "WEAVE_DEVICE_COUNT_DESKTOP")
val weaveMobile = MainPing.enumHistogramToCount(histograms("parent") \ "WEAVE_DEVICE_COUNT_MOBILE")
val events = MainPing.AllowedProcessTypes.map {
p => p -> payload \ "processes" \ p \ "events"
}
val sslHandshakeResultKeys = (0 to 671).map(_.toString)
// Messy list of known enum values for POPUP_NOTIFICATION_STATS.
val popupNotificationStatsKeys = (0 to 8).union(10 to 11).union(20 to 28).union(30 to 31).map(_.toString)
val pluginNotificationUserActionKeys = (0 to 2).map(_.toString)
// Get the "sum" field from histogram h as an Int. Consider a
// wonky histogram (one for which the "sum" field is not a
// valid number) as null.
@inline def hsum(h: JValue): Any = (h \ "sum").extractOpt[Int]
val row = Row.fromSeq(Seq(
// Row fields must match the structure in 'buildSchema'
documentId,
(meta \ "clientId").extractOpt[String],
(meta \ "sampleId").extractOpt[Long],
(meta \ "appUpdateChannel").extractOpt[String],
(meta \ "normalizedChannel").extractOpt[String],
(meta \ "normalizedOSVersion").extractOpt[String],
(meta \ "geoCountry").extractOpt[String],
(meta \ "geoCity").extractOpt[String],
(meta \ "geoSubdivision1").extractOpt[String],
(meta \ "geoSubdivision2").extractOpt[String],
(system \ "os" \ "name").extractOpt[String],
(system \ "os" \ "version").extractOpt[String],
(system \ "os" \ "servicePackMajor").extractOpt[Long],
(system \ "os" \ "servicePackMinor").extractOpt[Long],
(system \ "os" \ "windowsBuildNumber").extractOpt[Long],
(system \ "os" \ "windowsUBR").extractOpt[Long],
(system \ "os" \ "installYear").extractOpt[Long],
(system \ "isWow64").extractOpt[Boolean],
(system \ "memoryMB").extractOpt[Int],
(system \ "cpu" \ "count").extractOpt[Int],
(system \ "cpu" \ "cores").extractOpt[Int],
(system \ "cpu" \ "vendor").extractOpt[String],
(system \ "cpu" \ "family").extractOpt[Int],
(system \ "cpu" \ "model").extractOpt[Int],
(system \ "cpu" \ "stepping").extractOpt[Int],
(system \ "cpu" \ "l2cacheKB").extractOpt[Int],
(system \ "cpu" \ "l3cacheKB").extractOpt[Int],
(system \ "cpu" \ "speedMHz").extractOpt[Int],
(system \ "gfx" \ "features" \ "d3d11" \ "status").extractOpt[String],
(system \ "gfx" \ "features" \ "d2d" \ "status").extractOpt[String],
(system \ "gfx" \ "features" \ "gpuProcess" \ "status").extractOpt[String],
(system \ "gfx" \ "features" \ "advancedLayers" \ "status").extractOpt[String],
(system \ "gfx" \ "features" \ "wrQualified" \ "status").extractOpt[String],
(system \ "gfx" \ "features" \ "webrender" \ "status").extractOpt[String],
(system \ "hdd" \ "profile" \ "type").extractOpt[String],
(system \ "hdd" \ "binary" \ "type").extractOpt[String],
(system \ "hdd" \ "system" \ "type").extractOpt[String],
(system \ "appleModelId").extractOpt[String],
(system \ "sec" \ "antivirus").extract[Option[Seq[String]]],
(system \ "sec" \ "antispyware").extract[Option[Seq[String]]],
(system \ "sec" \ "firewall").extract[Option[Seq[String]]],
(profile \ "creationDate").extractOpt[Long],
(profile \ "resetDate").extractOpt[Long],
(info \ "previousBuildId").extractOpt[String],
(info \ "sessionId").extractOpt[String],
(info \ "subsessionId").extractOpt[String],
(info \ "previousSessionId").extractOpt[String],
(info \ "previousSubsessionId").extractOpt[String],
(info \ "sessionStartDate").extractOpt[String],
(info \ "subsessionStartDate").extractOpt[String],
(info \ "sessionLength").extractOpt[Long],
(info \ "subsessionLength").extractOpt[Long],
(info \ "subsessionCounter").extractOpt[Int],
(info \ "profileSubsessionCounter").extractOpt[Int],
(doc \ "creationDate").extractOpt[String],
(partner \ "distributionId").extractOpt[String],
submissionDate,
fxaConfigured,
weaveConfigured,
weaveDesktop,
weaveMobile,
(application \ "buildId").extractOpt[String],
(application \ "displayVersion").extractOpt[String],
(application \ "name").extractOpt[String],
(application \ "version").extractOpt[String],
timestamp, // required
(build \ "buildId").extractOpt[String],
(build \ "version").extractOpt[String],
(build \ "architecture").extractOpt[String],
(settings \ "e10sEnabled").extractOpt[Boolean],
(settings \ "e10sMultiProcesses").extractOpt[Long],
(settings \ "locale").extractOpt[String],
(settings \ "update" \ "channel").extractOpt[String],
(settings \ "update" \ "enabled").extractOpt[Boolean],
(settings \ "update" \ "autoDownload").extractOpt[Boolean],
getAttribution(settings \ "attribution"),
(settings \ "attribution" \ "experiment").extractOpt[String],
(settings \ "attribution" \ "variation").extractOpt[String],
(settings \ "sandbox" \ "effectiveContentProcessLevel").extractOpt[Int],
(addons \ "activeExperiment" \ "id").extractOpt[String],
(addons \ "activeExperiment" \ "branch").extractOpt[String],
(info \ "reason").extractOpt[String],
(info \ "timezoneOffset").extractOpt[Int],
hsum(keyedHistograms("parent") \ "SUBPROCESS_CRASHES_WITH_DUMP" \ "pluginhang"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_ABNORMAL_ABORT" \ "plugin"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_ABNORMAL_ABORT" \ "content"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_ABNORMAL_ABORT" \ "gmplugin"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_CRASHES_WITH_DUMP" \ "plugin"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_CRASHES_WITH_DUMP" \ "content"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_CRASHES_WITH_DUMP" \ "gmplugin"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_ATTEMPT" \ "main-crash"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_ATTEMPT" \ "content-crash"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_ATTEMPT" \ "plugin-crash"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_SUCCESS" \ "main-crash"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_SUCCESS" \ "content-crash"),
hsum(keyedHistograms("parent") \ "PROCESS_CRASH_SUBMIT_SUCCESS" \ "plugin-crash"),
hsum(keyedHistograms("parent") \ "SUBPROCESS_KILL_HARD" \ "ShutDownKill"),
MainPing.countKeys(addons \ "activeAddons"),
MainPing.getFlashVersion(addons),
(application \ "vendor").extractOpt[String],
(settings \ "isDefaultBrowser").extractOpt[Boolean],
(settings \ "defaultSearchEngineData" \ "name").extractOpt[String],
(settings \ "defaultSearchEngineData" \ "loadPath").extractOpt[String],
(settings \ "defaultSearchEngineData" \ "origin").extractOpt[String],
(settings \ "defaultSearchEngineData" \ "submissionURL").extractOpt[String],
(settings \ "defaultSearchEngine").extractOpt[String],
hsum(histograms("parent") \ "DEVTOOLS_TOOLBOX_OPENED_COUNT"),
(meta \ "Date").extractOpt[String],
getClockSkew((meta \ "Date").extractOpt[String], timestamp.get),
getSubmissionLatency((doc \ "creationDate").extractOpt[String], timestamp.get),
MainPing.histogramToMean(histograms("parent") \ "PLACES_BOOKMARKS_COUNT"),
MainPing.histogramToMean(histograms("parent") \ "PLACES_PAGES_COUNT"),
hsum(histograms("parent") \ "PUSH_API_NOTIFY"),
hsum(histograms("parent") \ "WEB_NOTIFICATION_SHOWN"),
MainPing.keyedEnumHistogramToMap(keyedHistograms("parent") \ "POPUP_NOTIFICATION_STATS",
popupNotificationStatsKeys),
MainPing.getSearchCounts(keyedHistograms("parent") \ "SEARCH_COUNTS"),
getActiveAddons(addons \ "activeAddons"),
getDisabledAddons(addons \ "activeAddons", addonDetails \ "XPI"),
getTheme(addons \ "theme"),
(settings \ "blocklistEnabled").extractOpt[Boolean],
(settings \ "addonCompatibilityCheckEnabled").extractOpt[Boolean],
(settings \ "telemetryEnabled").extractOpt[Boolean],
// bug 1525702
(settings \ "intl" \ "acceptLanguages").extractOpt[List[String]],
(settings \ "intl" \ "appLocales").extractOpt[List[String]],
(settings \ "intl" \ "availableLocales").extractOpt[List[String]],
(settings \ "intl" \ "regionalPrefsLocales").extractOpt[List[String]],
(settings \ "intl" \ "requestedLocales").extractOpt[List[String]],
(settings \ "intl" \ "systemLocales").extractOpt[List[String]],
// bug 1536175
(system \ "gfx" \ "Headless").extractOpt[Boolean],
getOldUserPrefs(settings \ "userPrefs"),
Option(events.flatMap { case (p, e) => Events.getEvents(e, p) }).filter(!_.isEmpty),
// bug 1339655
MainPing.enumHistogramBucketCount(histograms("parent") \ "SSL_HANDSHAKE_RESULT", sslHandshakeResultKeys.head),
MainPing.enumHistogramSumCounts(histograms("parent") \ "SSL_HANDSHAKE_RESULT", sslHandshakeResultKeys.tail),
MainPing.enumHistogramToMap(histograms("parent") \ "SSL_HANDSHAKE_RESULT", sslHandshakeResultKeys),
// bug 1382002 - use scalar version when available.
Try(MainPing.getScalarByName(scalars, scalarDefinitions, "scalar_parent_browser_engagement_active_ticks")) match {
case Success(x: Integer) => x
case _ => (simpleMeasures \ "activeTicks").extractOpt[Int]
},
// bug 1353114 - payload.simpleMeasurements.*
(simpleMeasures \ "main").extractOpt[Int],
// Use scalar version when available.
Try(MainPing.getScalarByName(scalars, scalarDefinitions, "scalar_parent_timestamps_first_paint")) match {
case Success(x: Integer) => x
case _ => (simpleMeasures \ "firstPaint").extractOpt[Int]
},
// bug 1353114 - payload.simpleMeasurements.*
(simpleMeasures \ "sessionRestored").extractOpt[Int],
(simpleMeasures \ "totalTime").extractOpt[Int],
(simpleMeasures \ "blankWindowShown").extractOpt[Int],
// bug 1362520 and 1526278 - plugin notifications
(histograms("parent") \ "PLUGINS_NOTIFICATION_SHOWN" \ "values" \ "1").extractOpt[Int],
(histograms("parent") \ "PLUGINS_NOTIFICATION_SHOWN" \ "values" \ "0").extractOpt[Int],
MainPing.enumHistogramToRow(histograms("parent") \ "PLUGINS_NOTIFICATION_USER_ACTION", pluginNotificationUserActionKeys),
hsum(histograms("parent") \ "PLUGINS_INFOBAR_SHOWN"),
hsum(histograms("parent") \ "PLUGINS_INFOBAR_BLOCK"),
hsum(histograms("parent") \ "PLUGINS_INFOBAR_ALLOW"),
hsum(histograms("parent") \ "PLUGINS_INFOBAR_DISMISSED"),
// bug 1366253 - active experiments
getExperiments(experiments),
(settings \ "searchCohort").extractOpt[String],
// bug 1366838 - Quantum Release Criteria
(system \ "gfx" \ "features" \ "compositor").extractOpt[String],
getQuantumReady(
settings \ "e10sEnabled",
addons \ "activeAddons",
addons \ "theme"
),
MainPing.histogramToThresholdCount(histograms("parent") \ "GC_MAX_PAUSE_MS_2", 150),
MainPing.histogramToThresholdCount(histograms("parent") \ "GC_MAX_PAUSE_MS_2", 250),
MainPing.histogramToThresholdCount(histograms("parent") \ "GC_MAX_PAUSE_MS_2", 2500),
MainPing.histogramToThresholdCount(histograms("content") \ "GC_MAX_PAUSE_MS_2", 150),
MainPing.histogramToThresholdCount(histograms("content") \ "GC_MAX_PAUSE_MS_2", 250),
MainPing.histogramToThresholdCount(histograms("content") \ "GC_MAX_PAUSE_MS_2", 2500),
MainPing.histogramToThresholdCount(histograms("parent") \ "CYCLE_COLLECTOR_MAX_PAUSE", 150),
MainPing.histogramToThresholdCount(histograms("parent") \ "CYCLE_COLLECTOR_MAX_PAUSE", 250),
MainPing.histogramToThresholdCount(histograms("parent") \ "CYCLE_COLLECTOR_MAX_PAUSE", 2500),
MainPing.histogramToThresholdCount(histograms("content") \ "CYCLE_COLLECTOR_MAX_PAUSE", 150),
MainPing.histogramToThresholdCount(histograms("content") \ "CYCLE_COLLECTOR_MAX_PAUSE", 250),
MainPing.histogramToThresholdCount(histograms("content") \ "CYCLE_COLLECTOR_MAX_PAUSE", 2500),
MainPing.histogramToThresholdCount(histograms("parent") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 150),
MainPing.histogramToThresholdCount(histograms("parent") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 250),
MainPing.histogramToThresholdCount(histograms("parent") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 2500),
MainPing.histogramToThresholdCount(histograms("content") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 150),
MainPing.histogramToThresholdCount(histograms("content") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 250),
MainPing.histogramToThresholdCount(histograms("content") \ "INPUT_EVENT_RESPONSE_COALESCED_MS", 2500),
MainPing.histogramToThresholdCount(histograms("parent") \ "GHOST_WINDOWS", 1),
MainPing.histogramToThresholdCount(histograms("content") \ "GHOST_WINDOWS", 1)
).map {
_ match {
case e: Option[Any] => e.orNull
case o => o
}
})
val userPrefsRow = getUserPrefs(settings \ "userPrefs", userPrefs)
val scalarRow = MainPing.scalarsToRow(
MainPing.DefaultProcessTypes.map{ p => p -> (scalars(p) merge keyedScalars(p)) }.toMap,
scalarDefinitions.filter{ case(n, d) => d.process != Some(MainPing.DynamicProcess) }
)
val histogramRow = MainPing.histogramsToRow(
MainPing.DefaultProcessTypes.map{ p => p -> (histograms(p) merge keyedHistograms(p)) }.toMap,
histogramDefinitions,
naturalHistogramRepresentationList
)
val addonScalarsRow = MainPing.addonScalarsToRow(
addonScalarSchema,
addonScalars merge addonKeyedScalars,
scalarDefinitions.filter{ case(n, d) => d.process == Some(MainPing.DynamicProcess) }
)
Some(Row.merge(row, userPrefsRow, scalarRow, histogramRow, addonScalarsRow))
} catch {
case e: Exception =>
None
}
}
// Type for encapsulating search counts
def buildSearchSchema: StructType = StructType(List(
StructField("engine", StringType, nullable = true), // Name of the search engine
StructField("source", StringType, nullable = true), // Source of the search (urlbar, etc)
StructField("count", LongType, nullable = true) // Number of searches
))
// Enumerated buckets from POPUP_NOTIFICATION_STATS keyed histogram
// Field names based on toolkit/modules/PopupNotifications.jsm
def buildPopupSchema: StructType = StructType(List(
StructField("offered", IntegerType, nullable = true), // bucket 0
StructField("action_1", IntegerType, nullable = true), // bucket 1
StructField("action_2", IntegerType, nullable = true), // bucket 2
StructField("action_3", IntegerType, nullable = true), // bucket 3
StructField("action_last", IntegerType, nullable = true), // bucket 4
StructField("dismissal_click_elsewhere", IntegerType, nullable = true), // bucket 5
StructField("dismissal_leave_page", IntegerType, nullable = true), // bucket 6
StructField("dismissal_close_button", IntegerType, nullable = true), // bucket 7
StructField("dismissal_not_now", IntegerType, nullable = true), // bucket 8
StructField("open_submenu", IntegerType, nullable = true), // bucket 10
StructField("learn_more", IntegerType, nullable = true), // bucket 11
StructField("reopen_offered", IntegerType, nullable = true), // bucket 20
StructField("reopen_action_1", IntegerType, nullable = true), // bucket 21
StructField("reopen_action_2", IntegerType, nullable = true), // bucket 22
StructField("reopen_action_3", IntegerType, nullable = true), // bucket 23
StructField("reopen_action_last", IntegerType, nullable = true), // bucket 24
StructField("reopen_dismissal_click_elsewhere", IntegerType, nullable = true), // bucket 25
StructField("reopen_dismissal_leave_page", IntegerType, nullable = true), // bucket 26
StructField("reopen_dismissal_close_button", IntegerType, nullable = true), // bucket 27
StructField("reopen_dismissal_not_now", IntegerType, nullable = true), // bucket 28
StructField("reopen_open_submenu", IntegerType, nullable = true), // bucket 30
StructField("reopen_learn_more", IntegerType, nullable = true) // bucket 31
))
// Data for a single addon per Bug 1290181
def buildAddonSchema: StructType = StructType(List(
StructField("addon_id", StringType, nullable = false),
StructField("blocklisted", BooleanType, nullable = true),
// Note: Skip "description" field - if needed, look it up from AMO.
StructField("name", StringType, nullable = true),
StructField("user_disabled", BooleanType, nullable = true),
StructField("app_disabled", BooleanType, nullable = true),
StructField("version", StringType, nullable = true),
StructField("scope", IntegerType, nullable = true),
StructField("type", StringType, nullable = true),
StructField("foreign_install", BooleanType, nullable = true),
StructField("has_binary_components", BooleanType, nullable = true),