// CallSOS will send SOS message to the zone wide kguard leader. func (this *ZkZone) CallSOS(caller string, msg string) { log.Critical("SOS[%s] %s: sending...", caller, msg) // kguard leader might float, so refresh on each SOS message kguards, err := this.KguardInfos() if err != nil { log.Error("SOS[%s] %s: %v", caller, msg, err) return } leader := kguards[0] request := gorequest.New().Timeout(time.Second * 10) res, body, errs := request.Post(fmt.Sprintf("http://%s:%d", leader.Host, telemetry.SOSPort)). Set("User-Agent", fmt.Sprintf("sos-go-%s", gafka.BuildId)). Set(telemetry.SOSIdentHeader, caller). End() if len(errs) > 0 { log.Error("SOS[%s] %s: %+v", caller, msg, errs) return } if res.StatusCode != http.StatusAccepted { log.Error("SOS[%s] %s: HTTP %s %s", caller, msg, http.StatusText(res.StatusCode), body) return } log.Info("SOS[%s] %s: sent ok", caller, msg) }
func (this *WatchAppError) consumePartition(zkcluster *zk.ZkCluster, consumer sarama.Consumer, topic string, partitionId int32, offset int64, msgCh chan<- *sarama.ConsumerMessage, wg *sync.WaitGroup) { defer wg.Done() p, err := consumer.ConsumePartition(topic, partitionId, offset) if err != nil { log.Error("%s %s/%d: offset=%d %v", zkcluster.Name(), topic, partitionId, offset, err) return } defer p.Close() for { select { case <-this.Stop: return case err := <-p.Errors(): log.Critical("cluster[%s] %s/%d: %s", zkcluster.Name(), topic, partitionId, err) return case msg := <-p.Messages(): if msg != nil && this.predicate(msg.Value) { msgCh <- msg } } } }
// specs: outbound data use bson func MarshalOut(d bson.M) []byte { val, err := bson.Marshal(d) if err != nil { // should never happen log.Critical("mongo.marshalOut: %+v -> %v", d, err) } return val }
func handleSOS(w http.ResponseWriter, r *http.Request) { sosMsg, _ := ioutil.ReadAll(r.Body) r.Body.Close() sosMetrics.Inc(1) lastSos = time.Now() log.Critical("SOS[%s] from %s %s", r.Header.Get(telemetry.SOSIdentHeader), r.RemoteAddr, string(sosMsg)) w.WriteHeader(http.StatusAccepted) }
func (zom *zookeeperOffsetManager) FinalizePartition(topic string, partition int32, lastOffset int64, timeout time.Duration) error { zom.l.RLock() tracker, present := zom.offsets[topic][partition] zom.l.RUnlock() if !present { return nil } if lastOffset >= 0 { if lastOffset < tracker.highestMarkedAsProcessedOffset { log.Critical("[%s/%s] %s/%d session offset backwards %d < %d", zom.cg.group.Name, zom.cg.shortID(), topic, partition, lastOffset, tracker.highestMarkedAsProcessedOffset) } if lastOffset-tracker.highestMarkedAsProcessedOffset > 1 { if !tracker.waitForOffset(lastOffset, timeout) { log.Debug("[%s/%s] %s/%d TIMEOUT %ds waiting for offset %d-%d. Last committed offset: %d", zom.cg.group.Name, zom.cg.shortID(), topic, partition, timeout/time.Second, lastOffset, tracker.highestMarkedAsProcessedOffset, tracker.lastCommittedOffset) } } if err := zom.commitOffset(topic, partition, tracker); err != nil && err != NoOffsetToCommit { return fmt.Errorf("FAILED to commit offset %d to Zookeeper. Last committed offset: %d %v", tracker.highestMarkedAsProcessedOffset, tracker.lastCommittedOffset, err) } } zom.l.Lock() delete(zom.offsets[topic], partition) zom.l.Unlock() return nil }
func (this *Mount) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("mount", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "") cmdFlags.StringVar(&this.cluster, "c", "", "") cmdFlags.StringVar(&this.logLevel, "l", "info", "") if err := cmdFlags.Parse(args); err != nil { return 1 } if validateArgs(this, this.Ui). on("-z", "-c"). invalid(args) { return 2 } this.mountPoint = args[len(args)-1] if !strings.HasPrefix(this.mountPoint, "/") { this.Ui.Error("mount point must start with /") return 1 } setupLogging("stdout", this.logLevel, "") c, err := fuse.Mount( this.mountPoint, fuse.FSName("kfs"), fuse.Subtype("kfs"), fuse.VolumeName("Kafka FS"), fuse.ReadOnly(), fuse.AllowOther(), ) if err != nil { log.Critical(err) } signal.RegisterHandler(func(sig os.Signal) { var err error for i := 0; i < 5; i++ { err = fuse.Unmount(this.mountPoint) if err == nil { break } log.Warn(err) time.Sleep(time.Second * 5) } if err == nil { log.Info("Kafka FS unmounted") } else { log.Error("Kafka FS unable to umount") } c.Close() os.Exit(0) }, syscall.SIGINT, syscall.SIGTERM) srv := fs.New(c, &fs.Config{}) fs := kfs.New(this.zone, this.cluster) if err := srv.Serve(fs); err != nil { log.Error(err) } <-c.Ready if err := c.MountError; err != nil { log.Error(err) } return }