Merge "catapult: Add flag for chromiumCommitPositions diagnostic"
diff --git a/catapult/cmd/catapult/make_histogram.go b/catapult/cmd/catapult/make_histogram.go
index a5fd486..15116a8 100644
--- a/catapult/cmd/catapult/make_histogram.go
+++ b/catapult/cmd/catapult/make_histogram.go
@@ -11,6 +11,7 @@
 	"fmt"
 	"io/ioutil"
 	"log"
+	"strconv"
 
 	"fuchsia.googlesource.com/testing/catapult"
 	schema "fuchsia.googlesource.com/testing/perf/schema/v1"
@@ -60,9 +61,12 @@
 	// Corresponds to the diagnostic "masters".
 	bucket string
 
-	// TODO(kjharland): Add placeholder for chromiumCommitPositions
-	// once the catapult team confirms what we can use this field
-	// for.
+	// dateTime marks the time when tests were executed in ms since the UNIX
+	// Epoch. The Catapult dashboard uses this value to order sample points in
+	// a graph.
+	//
+	// Corresponds to the diagnostic "chromiumCommitPositions".
+	dateTime uint64
 }
 
 type MakeHistogramCommand struct {
@@ -88,6 +92,9 @@
 		"LUCI builder that generated the test results")
 	flags.StringVar(&cmd.sharedDiagnostics.bucket, "bucket", "",
 		"Buildbucket bucket containing the job that ran the test")
+	flags.Uint64Var(&cmd.sharedDiagnostics.dateTime,
+		"datetime", 0,
+		"The date (in ms since epoch) the given tests were executed")
 }
 
 // Execute converts performance test output to a catapult HistogramSet.
@@ -143,11 +150,11 @@
 		Name  string
 		Value string
 	}{
+		// chromiumCommitPositions must come first or Catapult will reject the upload.
+		{"chromiumCommitPositions", strconv.FormatUint(cmd.sharedDiagnostics.dateTime, 10)},
 		{"benchmarks", cmd.sharedDiagnostics.testSuite},
 		{"bots", cmd.sharedDiagnostics.builder},
 		{"masters", cmd.sharedDiagnostics.bucket},
-		// Required for uploading, even if value is just empty.
-		{"chromiumCommitPositions", ""},
 	}
 	for _, info := range diagnosticInfoPairs {
 		histogramSet.AddSharedDiagnostic(info.Name, &catapult.GenericSetDiagnostic{
diff --git a/catapult/histogram_set.go b/catapult/histogram_set.go
index 63f822b..71c40d1 100644
--- a/catapult/histogram_set.go
+++ b/catapult/histogram_set.go
@@ -55,10 +55,12 @@
 // ToJSON returns a JSON-serializable representation of this HistogramSet.
 func (h *HistogramSet) ToJSON() []interface{} {
 	jsonObject := []interface{}{}
-	for _, entry := range h.histograms {
+	// Diagnostics must come first in the HistogramSet or Catapult will reject
+	// the upload request.
+	for _, entry := range h.diagnostics {
 		jsonObject = append(jsonObject, entry)
 	}
-	for _, entry := range h.diagnostics {
+	for _, entry := range h.histograms {
 		jsonObject = append(jsonObject, entry)
 	}
 	return jsonObject
diff --git a/catapult/histogram_set_test.go b/catapult/histogram_set_test.go
index e324524..a9488a5 100644
--- a/catapult/histogram_set_test.go
+++ b/catapult/histogram_set_test.go
@@ -116,6 +116,7 @@
 		// Each histogram in the set should have a reference to the diagnostic in its
 		// Diagnostics map.
 		expectedJSON := []interface{}{
+			diagnostic,
 			catapult.Histogram{
 				Name:        "test_histogram_1",
 				Diagnostics: map[string]string{"test_diagnostic": "test_guid"},
@@ -124,7 +125,6 @@
 				Name:        "test_histogram_2",
 				Diagnostics: map[string]string{"test_diagnostic": "test_guid"},
 			},
-			diagnostic,
 		}
 
 		if !reflect.DeepEqual(histogramSet.ToJSON(), expectedJSON) {