Example #1
0
func (c *CodahaleKafkaReporter) parseSchema(metrics map[string]interface{}) (avro.Schema, map[string]string) {
	lookupNames := make(map[string]string)
	schema := &avro.RecordSchema{
		Name:      "Metrics",
		Namespace: "ly.stealth",
		Fields:    make([]*avro.SchemaField, 0),
	}
	for name, v := range metrics {
		lookupName := c.getLookupName(name)
		lookupNames[lookupName] = name

		field := &avro.SchemaField{
			Name:    lookupName,
			Default: nil,
			Type: &avro.UnionSchema{
				Types: []avro.Schema{&avro.NullSchema{}, c.parseRecordField(name, v.(map[string]interface{}), lookupNames)},
			},
		}
		schema.Fields = append(schema.Fields, field)
	}
	schema.Fields = append(schema.Fields, &avro.SchemaField{
		Name: "logLine",
		Type: avroline.NewLogLine().Schema(),
	})

	return schema, lookupNames
}
Example #2
0
func newLogLine(source string, logtypeid int64, line string, tags map[string]string) *avro.LogLine {
	logLine := avro.NewLogLine()
	logLine.Source = source
	logLine.Logtypeid = logtypeid
	logLine.Line = line
	logLine.Tag = tags
	logLine.Timings = map[string]int64{"emitted": time.Now().Unix()}
	return logLine
}