Пример #1
0
func (td *TutumDecoder) Decode(pack *PipelinePack) (packs []*PipelinePack, err error) {
	// fmt.Printf("Message: %v\n", pack.Message)

	// get ContainerName
	container_name := pack.Message.FindFirstField("ContainerName").GetValueString()[0]

	// parse names from container_name
	stack, service, container, uuid := ParseTutumNames(container_name)

	// add fields to message with tutum service data
	if stack != "" {
		// add fields to message with tutum stack data
		field := message.NewFieldInit("TutumStackName", message.Field_STRING, "")
		field.AddValue(stack)
		pack.Message.AddField(field)
	}

	if service != "" {
		field := message.NewFieldInit("TutumServiceName", message.Field_STRING, "")
		field.AddValue(service)
		pack.Message.AddField(field)
	}

	if container != "" {
		// add fields to message with tutum stack data
		field := message.NewFieldInit("TutumContainerName", message.Field_STRING, "")
		field.AddValue(container)
		pack.Message.AddField(field)
	}

	if uuid != "" {
		// add fields to message with tutum stack data
		field := message.NewFieldInit("TutumUuid", message.Field_STRING, "")
		field.AddValue(uuid)
		pack.Message.AddField(field)
	}

	// fmt.Printf("Message: %v\n", pack.Message)
	if err = td.messageFields.PopulateMessage(pack.Message, nil); err != nil {
		return
	}

	// fmt.Printf("Message: %v\n", pack.Message)
	return []*PipelinePack{pack}, nil
}
Пример #2
0
func getTestMessageWithFunnyFields() *message.Message {
	field, _ := message.NewField(`"foo`, "bar\n", "")
	field1, _ := message.NewField(`"number`, 64, "")
	field2, _ := message.NewField("\xa3", "\xa3", "")
	field3, _ := message.NewField("idField", "1234", "")
	field4 := message.NewFieldInit("test_raw_field_bytes_array", message.Field_BYTES, "")
	field4.AddValue([]byte("{\"asdf\":123}"))
	field4.AddValue([]byte("{\"jkl;\":123}"))
	field5 := message.NewFieldInit("byteArray", message.Field_BYTES, "")
	field5.AddValue([]byte("asdf"))
	field5.AddValue([]byte("jkl;"))
	field6 := message.NewFieldInit("integerArray", message.Field_INTEGER, "")
	field6.AddValue(22)
	field6.AddValue(80)
	field6.AddValue(3000)
	field7 := message.NewFieldInit("doubleArray", message.Field_DOUBLE, "")
	field7.AddValue(42.0)
	field7.AddValue(19101.3)
	field8 := message.NewFieldInit("boolArray", message.Field_BOOL, "")
	field8.AddValue(true)
	field8.AddValue(false)
	field8.AddValue(false)
	field8.AddValue(false)
	field8.AddValue(true)
	field9 := message.NewFieldInit("test_raw_field_string", message.Field_STRING, "")
	field9.AddValue("{\"asdf\":123}")
	field10 := message.NewFieldInit("test_raw_field_bytes", message.Field_BYTES, "")
	field10.AddValue([]byte("{\"asdf\":123}"))
	field11 := message.NewFieldInit("test_raw_field_string_array", message.Field_STRING, "")
	field11.AddValue("{\"asdf\":123}")
	field11.AddValue("{\"jkl;\":123}")
	field12 := message.NewFieldInit("stringArray", message.Field_STRING, "")
	field12.AddValue("asdf")
	field12.AddValue("jkl;")
	field12.AddValue("push")
	field12.AddValue("pull")

	msg := &message.Message{}
	msg.SetType("TEST")
	loc, _ := time.LoadLocation("UTC")
	t, _ := time.ParseInLocation("2006-01-02T15:04:05.000Z", "2013-07-16T15:49:05.070Z",
		loc)
	msg.SetTimestamp(t.UnixNano())
	msg.SetUuid(uuid.Parse("87cf1ac2-e810-4ddf-a02d-a5ce44d13a85"))
	msg.SetLogger("GoSpec")
	msg.SetSeverity(int32(6))
	msg.SetPayload("Test Payload")
	msg.SetEnvVersion("0.8")
	msg.SetPid(14098)
	msg.SetHostname("hostname")
	msg.AddField(field)
	msg.AddField(field1)
	msg.AddField(field2)
	msg.AddField(field3)
	msg.AddField(field4)
	msg.AddField(field5)
	msg.AddField(field6)
	msg.AddField(field7)
	msg.AddField(field8)
	msg.AddField(field9)
	msg.AddField(field10)
	msg.AddField(field11)
	msg.AddField(field12)

	return msg
}