func invokeDownstreams()

in sandbox/ho11y/main.go [200:249]


func invokeDownstreams(ctx context.Context) {
	for _, downstream := range downstreams {
		var body string
		var size int
		var invokePeriod time.Duration
		if downstream != "" {
			// handle dummy downstreams (that is, pre-configured, deterministic responses)
			// format is:
			//            DUMMY:$BODY_SIZE:$INVOKE_DURATION
			// for example:
			//            DUMMY:187kB:42ms
			// would simulate a downstream that returned 187kB payload in 42ms.
			switch {
			case strings.HasPrefix(downstream, "DUMMY"):
				d := strings.Split(downstream, ":")
				var s datasize.ByteSize
				err := s.UnmarshalText([]byte(d[1]))
				if err != nil {
					log.Debugf("Can't parse dummy's invoke configuration: %v", err)
				}
				size = int(s)
				p, err := time.ParseDuration(d[2])
				if err != nil {
					log.Debugf("Can't parse dummy's invoke configuration (have to use Go duration syntax): %v", err)
				}
				invokePeriod = p
				time.Sleep(invokePeriod)
			default:
				body, size, invokePeriod = invoke(ctx, downstream)
				_ = body
			}
			// log:
			log.WithFields(
				log.Fields{
					"event":        "downstream",
					"body_bytes":   size,
					"duration_sec": invokePeriod.Seconds(),
				},
			).Info("ho11y invoked " + downstream)
			// metrics:
			v := float64(size)
			payloadsSummary.WithLabelValues(downstream).Observe(v)
			traceid := getXrayTraceID(trace.SpanFromContext(ctx))
			payloadsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
				float64(invokePeriod.Seconds()),
				prometheus.Labels{"traceid": traceid},
			)
		}
	}
}