func hcsStatsToNetworkStats(timestamp time.Time, hcsStats []hcsshim.NetworkStats) *statsapi.NetworkStats {
	result := &statsapi.NetworkStats{
		Time:       metav1.NewTime(timestamp),
		Interfaces: make([]statsapi.InterfaceStats, 0),
	}

	adapters := sets.NewString()
	for _, stat := range hcsStats {
		iStat, err := hcsStatsToInterfaceStats(stat)
		if err != nil {
			klog.Warningf("Failed to get HNS endpoint %q with error '%v', continue to get stats for other endpoints", stat.EndpointId, err)
			continue
		}

		// Only count each adapter once.
		if adapters.Has(iStat.Name) {
			continue
		}

		result.Interfaces = append(result.Interfaces, *iStat)
		adapters.Insert(iStat.Name)
	}

	// TODO(feiskyer): add support of multiple interfaces for getting default interface.
	if len(result.Interfaces) > 0 {
		result.InterfaceStats = result.Interfaces[0]
	}

	return result
}
// hcsStatsToNetworkStats converts hcsshim.Statistics.Network to statsapi.NetworkStats
hcsStatsToNetworkStats converts hcsshim.Statistics.Network to statsapi.NetworkStats
// hcsStatsToNetworkStats converts hcsshim . Statistics . Network to statsapi . NetworkStats
func hcsStatsToNetworkStats(timestamp time.Time, hcsStats []hcsshim.NetworkStats) *statsapi.NetworkStats {
	result := &statsapi.NetworkStats{
		Time:       metav1.NewTime(timestamp),
		Interfaces: make([]statsapi.InterfaceStats, 0),
	}
	adapters := sets.NewString()
	for _, stat := range hcsStats {
		iStat, err := hcsStatsToInterfaceStats(stat)
		if err != nil {
			klog.Warningf("Failed to get HNS endpoint %q with error '%v', continue to get stats for other endpoints", stat.EndpointId, err)
			continue
		}
		if adapters.Has(iStat.Name) {
			continue
		}
		result.Interfaces = append(result.Interfaces, *iStat)
		adapters.Insert(iStat.Name)
	}
	if len(result.Interfaces) > 0 {
		result.InterfaceStats = result.Interfaces[0]
	}
	return result
}
func hcsStatsToNetworkStats ( timestamp time . Time , hcsStats [ ] hcsshim . NetworkStats ) * statsapi . NetworkStats { result := & statsapi . NetworkStats { Time : metav1 . NewTime ( timestamp ) , Interfaces : make ( [ ] statsapi . InterfaceStats , 0 ) , } adapters := sets . NewString ( ) for _ , stat := range hcsStats { iStat , err := hcsStatsToInterfaceStats ( stat ) if err != nil { klog . Warningf ( " " , stat . EndpointId , err ) continue } if adapters . Has ( iStat . Name ) { continue } result . Interfaces = append ( result . Interfaces , * iStat ) adapters . Insert ( iStat . Name ) } if len ( result . Interfaces ) > 0 { result . InterfaceStats = result . Interfaces [ 0 ] } return result }
hcsStatsToNetworkStats converts hcsshim.Statistics.Network to statsapi.NetworkStats
hcsStatsToNetworkStats converts hcsshim . Statistics . Network to statsapi . NetworkStats
// Only count each adapter once. // TODO(feiskyer): add support of multiple interfaces for getting default interface.