Exemple #1
0
func (s *Span) Collect() error {
	log.Debugf("[Zipkin] Sending spans: %b", s.sampled)
	if !s.sampled {
		return nil
	}
	log.Debugf("[Zipkin] Serializing span: %v", s.span)
	bytes, err := SerializeSpan(s.span)
	if err != nil {
		return err
	}
	s.collector.Collect(bytes)
	return nil
}
Exemple #2
0
func (s *Span) NewChild(name string) *Span {
	log.Debugf("[Zipkin] Creating new child span: %s", name)
	if !s.sampled {
		return &Span{}
	}
	child := newSpan(name, s.span.TraceID, newID(), &s.span.ID, s.serviceName)
	child.collector = s.collector
	child.ip = s.ip
	child.port = s.port
	child.sampled = true
	return child
}
Exemple #3
0
func (t *Tracer) NewSpan(name string) *Span {
	log.Debugf("[Zipkin] Creating new span: %s", name)
	sampled := rand.Intn(t.rate) == 0
	if !sampled {
		return &Span{sampled: false}
	}
	span := newSpan(name, newID(), newID(), nil, t.serviceName)
	span.collector = t.collector
	span.port = t.port
	span.ip = t.ip
	span.sampled = true
	return span
}
Exemple #4
0
func (sc *ServerCommand) connectMarathon(url string, retries int, backoff time.Duration) (marathon.Marathon, error) {
	var err error
	var marathonClient marathon.Marathon
	for i := 0; i < retries; i++ {
		log.Infof("Trying to connect to Marathon: attempt %d", i)
		marathonClient, err = sc.newMarathonClient(url)
		if err == nil {
			return marathonClient, nil
		}
		log.Debugf("Error: %s", err)
		time.Sleep(backoff)
	}
	return nil, err
}
Exemple #5
0
func (t *Tracer) NewSpanFromRequest(name string, traceId *int64, spanId *int64, parentId *int64, sampled *bool) *Span {
	nonSampled := &Span{sampled: false}
	if sampled == nil {
		log.Debugf("[Zipkin] Empty trace info provided. Ignoring")
		return nonSampled
	}
	if !*sampled {
		log.Debugf("[Zipkin] The input trace info not sampled. Ignoring")
		return nonSampled
	}
	if spanId == nil || traceId == nil {
		log.Debugf("[Zipkin] The input trace info incomplete. Ignoring")
		return nonSampled
	}

	log.Debugf("[Zipkin] Creating new span %s from request: traceID %s, spanID %s, parentID %s, sampled %s", name,
		traceId, spanId, parentId, sampled)
	span := newSpan(name, *traceId, *spanId, nil, t.serviceName)
	span.collector = t.collector
	span.port = t.port
	span.ip = t.ip
	span.sampled = true
	return span
}
Exemple #6
0
func (sc *ServerCommand) Bootstrap(stackFile string, marathonClient marathon.Marathon, scheduler framework.Scheduler, retries int, backoff time.Duration) (*framework.Variables, error) {
	stackFileData, err := ioutil.ReadFile(stackFile)
	if err != nil {
		log.Errorf("Can't read file %s", stackFile)
		return nil, err
	}

	stack, err := framework.UnmarshalStack(stackFileData)
	if err != nil {
		return nil, err
	}

	log.Debugf("Boostrapping with stack: \n%s", string(stackFileData))
	bootstrapZone := ""

	context := framework.NewRunContext(framework.NewVariables())
	context.StackName = stack.Name
	context.Zone = bootstrapZone
	context.Marathon = marathonClient
	context.Scheduler = scheduler
	context.StateStorage = framework.NewInMemoryStateStorage()

	for i := 0; i < retries; i++ {
		err = stack.Run(&framework.RunRequest{
			Zone:    bootstrapZone,
			MaxWait: defaultApplicationMaxWait,
		}, context)
		if err == nil {
			return context.Variables, nil
		}

		if err != nil && !regexp.MustCompile(marathon.ErrMarathonDown.Error()).MatchString(err.Error()) {
			return nil, err
		}
		time.Sleep(backoff)
	}

	return context.Variables, err
}
Exemple #7
0
func (s *Span) ClientReceive() {
	log.Debugf("[Zipkin] ClientReceive")
	s.Annotate(zipkincore.CLIENT_RECV)
}
Exemple #8
0
func (s *Span) ClientSend() {
	log.Debugf("[Zipkin] ClientSend")
	s.Annotate(zipkincore.CLIENT_SEND)
}
Exemple #9
0
func (s *Span) ServerSend() {
	log.Debugf("[Zipkin] ServerSend")
	s.Annotate(zipkincore.SERVER_SEND)
}
Exemple #10
0
func (s *Span) ServerReceive() {
	log.Debugf("[Zipkin] ServerReceive")
	s.Annotate(zipkincore.SERVER_RECV)
}
Exemple #11
0
func (kc *KafkaCollector) Collect(bytes []byte) {
	log.Debugf("[Zipkin] Collecting bytes: %v", bytes)
	kc.producer.Send(&producer.ProducerRecord{Topic: kc.topic, Value: bytes})
	log.Debugf("[Zipkin] Bytes collected")
}