in datasource/etcd/util.go [201:260]
func statistics(ctx context.Context, withShared bool) (*pb.Statistics, error) {
result := &pb.Statistics{
Services: &pb.StService{},
Instances: &pb.StInstance{},
Apps: &pb.StApp{},
}
domainProject := util.ParseDomainProject(ctx)
opts := serviceUtil.FromContext(ctx)
// services
key := path.GetServiceIndexRootKey(domainProject) + "/"
svcOpts := append(opts,
etcdadpt.WithStrKey(key),
etcdadpt.WithPrefix())
respSvc, err := sd.ServiceIndex().Search(ctx, svcOpts...)
if err != nil {
return nil, err
}
var svcIDs []string
var svcKeys []*pb.MicroServiceKey
for _, keyValue := range respSvc.Kvs {
key := path.GetInfoFromSvcIndexKV(keyValue.Key)
svcKeys = append(svcKeys, key)
svcIDs = append(svcIDs, keyValue.Value.(string))
}
svcIDToNonVerKey := datasource.SetStaticServices(result, svcKeys, svcIDs, withShared)
respGetInstanceCountByDomain := make(chan datasource.GetInstanceCountByDomainResponse, 1)
gopool.Go(func(_ context.Context) {
getInstanceCountByDomain(ctx, svcIDToNonVerKey, respGetInstanceCountByDomain)
})
// instance
key = path.GetInstanceRootKey(domainProject) + "/"
instOpts := append(opts,
etcdadpt.WithStrKey(key),
etcdadpt.WithPrefix(),
etcdadpt.WithKeyOnly())
respIns, err := sd.Instance().Search(ctx, instOpts...)
if err != nil {
return nil, err
}
var instIDs []string
for _, keyValue := range respIns.Kvs {
serviceID, _, _ := path.GetInfoFromInstKV(keyValue.Key)
instIDs = append(instIDs, serviceID)
}
datasource.SetStaticInstances(result, svcIDToNonVerKey, instIDs)
data := <-respGetInstanceCountByDomain
close(respGetInstanceCountByDomain)
if data.Err != nil {
return nil, data.Err
}
result.Instances.CountByDomain = data.CountByDomain
return result, nil
}