Пример #1
0
func (f *FakeFirehose) SendEvent(eventType events.Envelope_EventType, message string) {
	envelope := events.Envelope{
		Origin:     proto.String("origin"),
		Timestamp:  proto.Int64(1000000000),
		Deployment: proto.String("deployment-name"),
		Job:        proto.String("doppler"),
	}

	switch eventType {
	case events.Envelope_LogMessage:
		envelope.EventType = events.Envelope_LogMessage.Enum()
		envelope.LogMessage = &events.LogMessage{
			Message:     []byte(message),
			MessageType: events.LogMessage_OUT.Enum(),
			Timestamp:   proto.Int64(1000000000),
		}
	case events.Envelope_ValueMetric:
		envelope.EventType = events.Envelope_ValueMetric.Enum()
		envelope.ValueMetric = &events.ValueMetric{
			Name:  proto.String(message),
			Value: proto.Float64(42),
			Unit:  proto.String("unit"),
		}
	case events.Envelope_CounterEvent:
		envelope.EventType = events.Envelope_CounterEvent.Enum()
		envelope.CounterEvent = &events.CounterEvent{
			Name:  proto.String(message),
			Delta: proto.Uint64(42),
		}
	case events.Envelope_ContainerMetric:
		envelope.EventType = events.Envelope_ContainerMetric.Enum()
		envelope.ContainerMetric = &events.ContainerMetric{
			ApplicationId: proto.String(message),
			InstanceIndex: proto.Int32(1),
			CpuPercentage: proto.Float64(1),
			MemoryBytes:   proto.Uint64(1),
			DiskBytes:     proto.Uint64(1),
		}
	case events.Envelope_Error:
		envelope.EventType = events.Envelope_Error.Enum()
		envelope.Error = &events.Error{
			Source:  proto.String("source"),
			Code:    proto.Int32(404),
			Message: proto.String(message),
		}
	case events.Envelope_HttpStart:
		envelope.EventType = events.Envelope_HttpStart.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStart = &events.HttpStart{
			Timestamp:     proto.Int64(12),
			RequestId:     NewUUID(uuid),
			PeerType:      events.PeerType_Client.Enum(),
			Method:        events.Method_GET.Enum(),
			Uri:           proto.String("some uri"),
			RemoteAddress: proto.String("some address"),
			UserAgent:     proto.String(message),
		}
	case events.Envelope_HttpStop:
		envelope.EventType = events.Envelope_HttpStop.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStop = &events.HttpStop{
			Timestamp:     proto.Int64(12),
			Uri:           proto.String("http://stop.example.com"),
			RequestId:     NewUUID(uuid),
			PeerType:      events.PeerType_Client.Enum(),
			StatusCode:    proto.Int32(404),
			ContentLength: proto.Int64(98475189),
		}
	case events.Envelope_HttpStartStop:
		envelope.EventType = events.Envelope_HttpStartStop.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStartStop = &events.HttpStartStop{
			StartTimestamp: proto.Int64(1234),
			StopTimestamp:  proto.Int64(5555),
			RequestId:      NewUUID(uuid),
			PeerType:       events.PeerType_Server.Enum(),
			Method:         events.Method_GET.Enum(),
			Uri:            proto.String("http://startstop.example.com"),
			RemoteAddress:  proto.String("http://startstop.example.com"),
			UserAgent:      proto.String("test"),
			StatusCode:     proto.Int32(1234),
			ContentLength:  proto.Int64(5678),
			ApplicationId:  NewUUID(uuid),
		}

	}

	f.addEvent(envelope)
}