@@ -136,6 +136,8 @@ func (d *Daemon) TraceAll(connections []connection.Connection) {
136136 }
137137}
138138
139+ // Metadata is the first line of the traceroute .jsonl file.
140+ //
139141// TODO: move this struct to ETL parser.
140142type Metadata struct {
141143 UUID string
@@ -144,9 +146,11 @@ type Metadata struct {
144146 CachedUUID string
145147}
146148
147- // isCache indicates whether this meta line is for an orignial trace test or a cached test.
148- // uuis is the original test if isCache is 1.
149- func GetMetaline (conn connection.Connection , isCache int , cachedUUID string ) string {
149+ // GetMetaline returns the what the first line of the output jsonl file should
150+ // be. Parameter isCache indicates whether this meta line is for an original
151+ // trace test or a cached test, and parameter cachedUUID is the original test if
152+ // isCache is 1.
153+ func GetMetaline (conn connection.Connection , isCache bool , cachedUUID string ) string {
150154 // Write the UUID as the first line of the file. If we want to add other
151155 // metadata, this is the place to do it.
152156 //
@@ -159,7 +163,7 @@ func GetMetaline(conn connection.Connection, isCache int, cachedUUID string) str
159163 meta := Metadata {
160164 UUID : uuid ,
161165 TracerouteCallerVersion : prometheusx .GitShortCommit ,
162- CachedResult : bool ( isCache == 1 ) ,
166+ CachedResult : isCache ,
163167 CachedUUID : cachedUUID ,
164168 }
165169
@@ -168,7 +172,10 @@ func GetMetaline(conn connection.Connection, isCache int, cachedUUID string) str
168172 return string (metaJSON ) + "\n "
169173}
170174
171- func ExtractUUID (metaline string ) string {
175+ // extractUUID retrieves the UUID from a cached line.
176+ //
177+ // TODO: Eliminate the need to unmarshal data we marshaled in the first place.
178+ func extractUUID (metaline string ) string {
172179 var metaResult Metadata
173180 err := json .Unmarshal ([]byte (metaline ), & metaResult )
174181 if err != nil {
@@ -178,6 +185,8 @@ func ExtractUUID(metaline string) string {
178185 return metaResult .UUID
179186}
180187
188+ // CreateCacheTest creates a file containing traceroute results that came from a
189+ // cache result, rather than performing the traceroute with scamper.
181190func (d * Daemon ) CreateCacheTest (conn connection.Connection , t time.Time , cachedTest string ) {
182191 filename := d .createTimePath (t ) + d .generateFilename (conn .Cookie , t )
183192 log .Println ("Starting a cached trace to be put in" , filename )
@@ -191,7 +200,7 @@ func (d *Daemon) CreateCacheTest(conn connection.Connection, t time.Time, cached
191200 }
192201
193202 // Get the uuid from the first line of cachedTest
194- newTest := GetMetaline (conn , 1 , ExtractUUID (cachedTest [:split ])) + cachedTest [split + 1 :]
203+ newTest := GetMetaline (conn , true , extractUUID (cachedTest [:split ])) + cachedTest [split + 1 :]
195204 rtx .PanicOnError (ioutil .WriteFile (filename , []byte (newTest ), 0666 ), "Could not save output to file" )
196205}
197206
@@ -200,7 +209,7 @@ func (d *Daemon) trace(conn connection.Connection, t time.Time) string {
200209 log .Println ("Starting a trace to be put in" , filename )
201210 buff := bytes.Buffer {}
202211
203- _ , err := buff .WriteString (GetMetaline (conn , 0 , "" ))
212+ _ , err := buff .WriteString (GetMetaline (conn , false , "" ))
204213 rtx .PanicOnError (err , "Could not write to buffer" )
205214
206215 log .Printf (
@@ -219,7 +228,3 @@ func (d *Daemon) trace(conn connection.Connection, t time.Time) string {
219228 return string (buff .Bytes ())
220229}
221230
222- type Tracer interface {
223- Trace (conn connection.Connection , t time.Time ) string
224- CreateCacheTest (conn connection.Connection , t time.Time , cachedTest string )
225- }
0 commit comments