本文整理匯總了Golang中github.com/mozilla-services/heka/pipeline.PipelinePack類的典型用法代碼示例。如果您正苦於以下問題:Golang PipelinePack類的具體用法?Golang PipelinePack怎麽用?Golang PipelinePack使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PipelinePack類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (rpsi *RedisPubSubInput) Run(ir pipeline.InputRunner, h pipeline.PluginHelper) error {
var (
dRunner pipeline.DecoderRunner
decoder pipeline.Decoder
pack *pipeline.PipelinePack
e error
ok bool
)
// Get the InputRunner's chan to receive empty PipelinePacks
packSupply := ir.InChan()
if rpsi.conf.DecoderName != "" {
if dRunner, ok = h.DecoderRunner(rpsi.conf.DecoderName, fmt.Sprintf("%s-%s", ir.Name(), rpsi.conf.DecoderName)); !ok {
return fmt.Errorf("Decoder not found: %s", rpsi.conf.DecoderName)
}
decoder = dRunner.Decoder()
}
//Connect to the channel
psc := redis.PubSubConn{Conn: rpsi.conn}
psc.PSubscribe(rpsi.conf.Channel)
for {
switch n := psc.Receive().(type) {
case redis.PMessage:
// Grab an empty PipelinePack from the InputRunner
pack = <-packSupply
pack.Message.SetType("redis_pub_sub")
pack.Message.SetLogger(n.Channel)
pack.Message.SetPayload(string(n.Data))
pack.Message.SetTimestamp(time.Now().UnixNano())
var packs []*pipeline.PipelinePack
if decoder == nil {
packs = []*pipeline.PipelinePack{pack}
} else {
packs, e = decoder.Decode(pack)
}
if packs != nil {
for _, p := range packs {
ir.Inject(p)
}
} else {
if e != nil {
ir.LogError(fmt.Errorf("Couldn't parse Redis message: %s", n.Data))
}
pack.Recycle(nil)
}
case redis.Subscription:
ir.LogMessage(fmt.Sprintf("Subscription: %s %s %d\n", n.Kind, n.Channel, n.Count))
if n.Count == 0 {
return errors.New("No channel to subscribe")
}
case error:
fmt.Printf("error: %v\n", n)
return n
}
}
return nil
}
示例2: Run
func (f *UptimeFilter) Run(runner pipeline.FilterRunner, helper pipeline.PluginHelper) (err error) {
var (
pack *pipeline.PipelinePack
payload string
)
inChan := runner.InChan()
for pack = range inChan {
payload = pack.Message.GetPayload()
runner.LogMessage("Payload: " + payload)
if f.hours == nil {
f.hours = make(map[int64]bool)
}
var epoch int64 = f.GetEpoch(payload)
f.startHour, f.endHour = f.FigureOutStartAndEndHour(epoch)
if !f.hours[f.startHour] {
f.InitFilterForStartHour(f.startHour, payload)
} else {
f.CalculateUptimeFor(f.startHour, f.endHour)
// f.hours[&f.startHour] = false
log.Printf("Length of map: &d", len(f.hours))
}
log.Printf("Start hour: %d", f.startHour)
log.Printf("End hour: %d", f.endHour)
log.Printf("EPOCH: %d", epoch)
pack.Recycle()
}
return
}
示例3: InsertMessage
func (rli *RedisInput) InsertMessage(ir pipeline.InputRunner, decoder pipeline.Decoder, msg string) {
var (
pack *pipeline.PipelinePack
e error
)
// Get the InputRunner's chan to receive empty PipelinePacks
packSupply := ir.InChan()
pack = <-packSupply
pack.Message.SetType(rli.conf.Key)
pack.Message.SetLogger("Redis")
pack.Message.SetPayload(msg)
pack.Message.SetTimestamp(time.Now().UnixNano())
var packs []*pipeline.PipelinePack
if decoder == nil {
packs = []*pipeline.PipelinePack{pack}
} else {
packs, e = decoder.Decode(pack)
}
if packs != nil {
for _, p := range packs {
ir.Inject(p)
}
} else {
if e != nil {
ir.LogError(fmt.Errorf("Couldn't parse %s", msg))
pack.Recycle(e)
} else {
pack.Recycle(nil)
fmt.Println("pack recycle!")
}
}
}
示例4: Run
func (rli *RedisListInput) Run(ir pipeline.InputRunner, h pipeline.PluginHelper) error {
var (
pack *pipeline.PipelinePack
packs []*pipeline.PipelinePack
)
// Get the InputRunner's chan to receive empty PipelinePacks
inChan := ir.InChan()
for {
message, err := rli.conn.Do("RPOP", rli.conf.ListName)
if err != nil {
ir.LogError(fmt.Errorf("Redis RPOP error: %s", err))
// TODO: should reconnect redis rather than close it
rli.Stop()
break
}
if message != nil {
pack = <-inChan
pack.Message.SetType("redis_list")
pack.Message.SetPayload(string(message.([]uint8)))
packs = []*pipeline.PipelinePack{pack}
if packs != nil {
for _, p := range packs {
ir.Inject(p)
}
} else {
pack.Recycle(nil)
}
} else {
time.Sleep(time.Second)
}
}
return nil
}
示例5: Run
func (sop *SCAMPOutputPlugin) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
var pack *pipeline.PipelinePack
// We have no default encoder
if or.Encoder() == nil {
return errors.New("Encoder required.")
}
for pack = range or.InChan() {
scamp.Info.Printf("received pipeline pack")
encoded, err := or.Encode(pack) // pack.Message.GetPayload()
if err == nil {
scamp.Info.Printf("payload: %s", encoded)
msg := scamp.NewMessage()
msg.SetEnvelope(scamp.ENVELOPE_JSON)
msg.SetAction(sop.conf.Action)
msg.SetVersion(1)
msg.Write(encoded)
}
pack.Recycle(err)
}
fmt.Println("sup from end of for loop in Run")
return
}
示例6: Run
func (output *IrcOutput) Run(runner pipeline.OutputRunner,
helper pipeline.PluginHelper) error {
if runner.Encoder() == nil {
return errors.New("Encoder required.")
}
output.runner = runner
// Register callbacks to handle events
registerCallbacks(output)
var err error
// Connect to the Irc Server
err = output.Conn.Connect(output.Server)
if err != nil {
return fmt.Errorf("Unable to connect to irc server %s: %s",
output.Server, err)
}
// Start a goroutine for recieving messages, and throttling before sending
// to the Irc Server
output.wg.Add(1)
go processOutQueue(output)
var outgoing []byte
ok := true
inChan := runner.InChan()
var pack *pipeline.PipelinePack
for ok {
select {
case pack, ok = <-inChan:
case <-output.die:
ok = false
}
if !ok {
break
}
outgoing, err = runner.Encode(pack)
if err != nil {
output.runner.LogError(err)
} else if outgoing != nil {
// Send the message to each irc channel. If the out queue is full,
// then we need to drop the message and log an error.
for i, ircChannel := range output.Channels {
ircMsg := IrcMsg{outgoing, ircChannel, i}
select {
case output.OutQueue <- ircMsg:
default:
output.runner.LogError(ErrOutQueueFull)
}
}
}
pack.Recycle()
}
output.cleanup()
return nil
}
示例7: Run
func (clo *CloudLoggingOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
var (
pack *pipeline.PipelinePack
e error
k string
m *logging.LogEntry
exist bool
ok = true
inChan = or.InChan()
groupBatch = make(map[string]*LogBatch)
outBatch *LogBatch
ticker = time.Tick(time.Duration(clo.conf.FlushInterval) * time.Millisecond)
)
clo.or = or
go clo.committer()
for ok {
select {
case pack, ok = <-inChan:
// Closed inChan => we're shutting down, flush data.
if !ok {
clo.sendGroupBatch(groupBatch)
close(clo.batchChan)
<-clo.outputExit
break
}
k, m, e = clo.Encode(pack)
pack.Recycle()
if e != nil {
or.LogError(e)
continue
}
if k != "" && m != nil {
outBatch, exist = groupBatch[k]
if !exist {
outBatch = &LogBatch{count: 0, batch: make([]*logging.LogEntry, 0, 100), name: k}
groupBatch[k] = outBatch
}
outBatch.batch = append(outBatch.batch, m)
if outBatch.count++; clo.CheckFlush(int(outBatch.count), len(outBatch.batch)) {
if len(outBatch.batch) > 0 {
outBatch.batch = clo.sendBatch(k, outBatch.batch, outBatch.count)
outBatch.count = 0
}
}
}
case <-ticker:
clo.sendGroupBatch(groupBatch)
case err = <-clo.outputExit:
ok = false
}
}
return
}
示例8: Run
func (cmo *CloudMonitoringOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
var (
pack *pipeline.PipelinePack
e error
m *cloudmonitoring.TimeseriesPoint
ok = true
count int64
inChan = or.InChan()
outBatch = make([]*cloudmonitoring.TimeseriesPoint, 0, 200)
ticker = time.Tick(time.Duration(cmo.conf.FlushInterval) * time.Millisecond)
)
cmo.or = or
go cmo.committer()
for ok {
select {
case pack, ok = <-inChan:
// Closed inChan => we're shutting down, flush data.
if !ok {
if len(outBatch) > 0 {
cmo.sendBatch(outBatch, count)
}
close(cmo.batchChan)
<-cmo.outputExit
break
}
m, e = cmo.Encode(pack)
pack.Recycle()
if e != nil {
or.LogError(e)
continue
}
if m != nil {
outBatch = append(outBatch, m)
if count++; cmo.CheckFlush(int(count), len(outBatch)) {
if len(outBatch) > 0 {
outBatch = cmo.sendBatch(outBatch, count)
count = 0
}
}
}
case <-ticker:
if len(outBatch) > 0 {
outBatch = cmo.sendBatch(outBatch, count)
}
count = 0
case err = <-cmo.outputExit:
ok = false
}
}
return
}
示例9: Run
func (cef *CefOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
var (
facility, priority syslog.Priority
ident string
ok bool
p syslog.Priority
e error
pack *pipeline.PipelinePack
)
syslogMsg := new(SyslogMsg)
for pack = range or.InChan() {
// default values
facility, priority = syslog.LOG_LOCAL4, syslog.LOG_INFO
ident = "heka_no_ident"
priField := pack.Message.FindFirstField("cef_meta.syslog_priority")
if priField != nil {
priStr := priField.ValueString[0]
if p, ok = SYSLOG_PRIORITY[priStr]; ok {
priority = p
}
}
facField := pack.Message.FindFirstField("cef_meta.syslog_facility")
if facField != nil {
facStr := facField.ValueString[0]
if p, ok = SYSLOG_FACILITY[facStr]; ok {
facility = p
}
}
idField := pack.Message.FindFirstField("cef_meta.syslog_ident")
if idField != nil {
ident = idField.ValueString[0]
}
syslogMsg.priority = priority | facility
syslogMsg.prefix = ident
syslogMsg.payload = pack.Message.GetPayload()
pack.Recycle()
_, e = cef.syslogWriter.WriteString(syslogMsg.priority, syslogMsg.prefix,
syslogMsg.payload)
if e != nil {
or.LogError(e)
}
}
cef.syslogWriter.Close()
return
}
示例10: Run
func (cwo *CloudwatchOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
inChan := or.InChan()
payloads := make(chan CloudwatchDatapoints, cwo.backlog)
go cwo.Submitter(payloads, or)
var (
pack *pipeline.PipelinePack
msg *message.Message
rawDataPoints *CloudwatchDatapointPayload
dataPoints *CloudwatchDatapoints
)
dataPoints = new(CloudwatchDatapoints)
dataPoints.Datapoints = make([]cloudwatch.MetricDatum, 0, 0)
for pack = range inChan {
rawDataPoints = new(CloudwatchDatapointPayload)
msg = pack.Message
err = json.Unmarshal([]byte(msg.GetPayload()), rawDataPoints)
if err != nil {
or.LogMessage(fmt.Sprintf("warning, unable to parse payload: %s", err))
err = nil
continue
}
// Run through the list and convert them to CloudwatchDatapoints
for _, rawDatum := range rawDataPoints.Datapoints {
datum := cloudwatch.MetricDatum{
Dimensions: rawDatum.Dimensions,
MetricName: rawDatum.MetricName,
Unit: rawDatum.Unit,
Value: rawDatum.Value,
StatisticValues: rawDatum.StatisticValues,
}
if rawDatum.Timestamp != "" {
parsedTime, err := message.ForgivingTimeParse("", rawDatum.Timestamp, cwo.tzLocation)
if err != nil {
or.LogMessage(fmt.Sprintf("unable to parse timestamp for datum: %s", rawDatum))
continue
}
datum.Timestamp = parsedTime
}
dataPoints.Datapoints = append(dataPoints.Datapoints, datum)
}
payloads <- *dataPoints
dataPoints.Datapoints = dataPoints.Datapoints[:0]
rawDataPoints.Datapoints = rawDataPoints.Datapoints[:0]
pack.Recycle()
}
or.LogMessage("shutting down AWS Cloudwatch submitter")
cwo.stopChan <- true
<-cwo.stopChan
return
}
示例11: Run
func (k *KafkaOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
defer func() {
k.producer.Close()
k.client.Close()
}()
if or.Encoder() == nil {
return errors.New("Encoder required.")
}
inChan := or.InChan()
errChan := k.producer.Errors()
var wg sync.WaitGroup
wg.Add(1)
go k.processKafkaErrors(or, errChan, &wg)
var (
pack *pipeline.PipelinePack
topic = k.config.Topic
key sarama.Encoder
)
for pack = range inChan {
atomic.AddInt64(&k.processMessageCount, 1)
if k.topicVariable != nil {
topic = getMessageVariable(pack.Message, k.topicVariable)
}
if k.hashVariable != nil {
key = sarama.StringEncoder(getMessageVariable(pack.Message, k.hashVariable))
}
if msgBytes, err := or.Encode(pack); err == nil {
if msgBytes != nil {
err = k.producer.QueueMessage(topic, key, sarama.ByteEncoder(msgBytes))
if err != nil {
atomic.AddInt64(&k.processMessageFailures, 1)
or.LogError(err)
}
} else {
atomic.AddInt64(&k.processMessageDiscards, 1)
}
} else {
atomic.AddInt64(&k.processMessageFailures, 1)
or.LogError(err)
}
pack.Recycle()
}
errChan <- Shutdown
wg.Wait()
return
}
示例12: Run
func (zi *ZeroMQInput) Run(ir pipeline.InputRunner, h pipeline.PluginHelper) error {
// Get the InputRunner's chan to receive empty PipelinePacks
packs := ir.InChan()
var decoding chan<- *pipeline.PipelinePack
if zi.conf.Decoder != "" {
// Fetch specified decoder
decoder, ok := h.DecoderSet().ByName(zi.conf.Decoder)
if !ok {
err := fmt.Errorf("Could not find decoder", zi.conf.Decoder)
return err
}
// Get the decoder's receiving chan
decoding = decoder.InChan()
}
var pack *pipeline.PipelinePack
var count int
var b []byte
var err error
// Read data from websocket broadcast chan
for {
b, err = zi.socket.Recv(0)
if err != nil {
ir.LogError(err)
continue
}
// Grab an empty PipelinePack from the InputRunner
pack = <-packs
// Trim the excess empty bytes
count = len(b)
pack.MsgBytes = pack.MsgBytes[:count]
// Copy ws bytes into pack's bytes
copy(pack.MsgBytes, b)
if decoding != nil {
// Send pack onto decoder
decoding <- pack
} else {
// Send pack into Heka pipeline
ir.Inject(pack)
}
}
return nil
}
示例13: Run
func (this *SandboxManagerFilter) Run(fr pipeline.FilterRunner,
h pipeline.PluginHelper) (err error) {
inChan := fr.InChan()
var ok = true
var pack *pipeline.PipelinePack
var delta int64
this.restoreSandboxes(fr, h, this.workingDirectory)
for ok {
select {
case pack, ok = <-inChan:
if !ok {
break
}
atomic.AddInt64(&this.processMessageCount, 1)
delta = time.Now().UnixNano() - pack.Message.GetTimestamp()
if math.Abs(float64(delta)) >= 5e9 {
fr.LogError(fmt.Errorf("Discarded control message: %d seconds skew",
delta/1e9))
pack.Recycle()
break
}
action, _ := pack.Message.GetFieldValue("action")
switch action {
case "load":
current := int(atomic.LoadInt32(&this.currentFilters))
if current < this.maxFilters {
err := this.loadSandbox(fr, h, this.workingDirectory, pack.Message)
if err != nil {
fr.LogError(err)
}
} else {
fr.LogError(fmt.Errorf("%s attempted to load more than %d filters",
fr.Name(), this.maxFilters))
}
case "unload":
fv, _ := pack.Message.GetFieldValue("name")
if name, ok := fv.(string); ok {
name = getSandboxName(fr.Name(), name)
if this.pConfig.RemoveFilterRunner(name) {
removeAll(this.workingDirectory, fmt.Sprintf("%s.*", name))
}
}
}
pack.Recycle()
}
}
return
}
示例14: Encode
func (s *SandboxEncoder) Encode(pack *pipeline.PipelinePack) (output []byte, err error) {
if s.sb == nil {
err = errors.New("No sandbox.")
return
}
atomic.AddInt64(&s.processMessageCount, 1)
s.injected = false
var startTime time.Time
if s.sample {
startTime = time.Now()
}
cowpack := new(pipeline.PipelinePack)
cowpack.Message = pack.Message // the actual copy will happen if write_message is called
cowpack.MsgBytes = pack.MsgBytes // no copying is necessary since we don't change it
retval := s.sb.ProcessMessage(cowpack)
if retval == 0 && !s.injected {
// `inject_message` was never called, protobuf encode the copy on write
// message.
if s.output, err = s.cEncoder.EncodeMessage(cowpack.Message); err != nil {
return
}
}
if s.sample {
duration := time.Since(startTime).Nanoseconds()
s.reportLock.Lock()
s.processMessageDuration += duration
s.processMessageSamples++
s.reportLock.Unlock()
}
s.sample = 0 == rand.Intn(s.sampleDenominator)
if retval > 0 {
err = fmt.Errorf("FATAL: %s", s.sb.LastError())
return
}
if retval == -2 {
// Encoder has nothing to return.
return nil, nil
}
if retval < 0 {
atomic.AddInt64(&s.processMessageFailures, 1)
err = fmt.Errorf("Failed serializing: %s", s.sb.LastError())
return
}
return s.output, nil
}
示例15: HandlePackage
func (k *KinesisOutput) HandlePackage(or pipeline.OutputRunner, pack *pipeline.PipelinePack) error {
// If we are flushing, wait until we have finished.
k.flushLock.Lock()
defer k.flushLock.Unlock()
// encode the packages.
msg, err := or.Encode(pack)
if err != nil {
errOut := fmt.Errorf("Error encoding message: %s", err)
or.LogError(errOut)
pack.Recycle(nil)
return errOut
}
// If we only care about the Payload...
if k.config.PayloadOnly {
msg = []byte(pack.Message.GetPayload())
}
var tmp []byte
// if we already have data then we should append.
if len(k.batchedData) > 0 {
tmp = append(append(k.batchedData, []byte(",")...), msg...)
} else {
tmp = msg
}
// if we can't fit the data in this record
if len(tmp) > k.KINESIS_RECORD_SIZE {
// add the existing data to the output batch
array := append(append([]byte("["), k.batchedData...), []byte("]")...)
k.AddToRecordBatch(or, array)
// update the batched data to only contain the current message.
k.batchedData = msg
} else {
// otherwise we add the existing data to a batch
k.batchedData = tmp
}
// do reporting and tidy up
atomic.AddInt64(&k.processMessageCount, 1)
pack.Recycle(nil)
return nil
}