@@ -18,6 +18,7 @@ type Client struct {
1818}
1919
2020type providerResult struct {
21+ kind Kind
2122 snapshot * ProviderSnapshot
2223 err error
2324}
@@ -48,40 +49,60 @@ func (c Client) Collect(ctx context.Context) (*Snapshot, error) {
4849 if err := ctx .Err (); err != nil {
4950 return nil , err
5051 }
51- ctx , cancel := context .WithTimeout (ctx , 15 * time .Second )
52+ collectCtx , cancel := context .WithTimeout (ctx , 15 * time .Second )
5253 defer cancel ()
5354 results := make ([]providerResult , len (c .providers ))
5455 var wg sync.WaitGroup
5556 for index , item := range c .providers {
5657 wg .Add (1 )
5758 go func () {
5859 defer wg .Done ()
59- providerSnapshot , err := item .Collect (ctx )
60+ providerSnapshot , err := item .Collect (collectCtx )
6061 if err != nil {
6162 err = fmt .Errorf ("%s provider failed: %w" , item .Kind (), err )
6263 }
63- results [index ] = providerResult {snapshot : providerSnapshot , err : err }
64+ results [index ] = providerResult {kind : item . Kind (), snapshot : providerSnapshot , err : err }
6465 }()
6566 }
6667 wg .Wait ()
6768 if err := ctx .Err (); err != nil {
6869 return nil , err
6970 }
7071
71- snapshot := & Snapshot {}
72+ snapshot := & Snapshot {Info : Info { VendorWarnings : map [ string ][] string {}} }
7273 var (
7374 errs []error
7475 active []* ProviderSnapshot
7576 xpuVersion string
7677 )
78+ if err := collectCtx .Err (); err != nil {
79+ snapshot .Info .Warnings = append (snapshot .Info .Warnings , err .Error ())
80+ }
7781 for _ , result := range results {
78- if result .err != nil {
79- errs = append (errs , result .err )
80- continue
82+ vendor := ""
83+ switch result .kind {
84+ case KindXPU :
85+ vendor = "intel"
86+ case KindNPU :
87+ vendor = "ascend"
88+ }
89+ if result .err != nil && (result .snapshot == nil || len (result .snapshot .VendorWarnings ) == 0 ) {
90+ if vendor == "" {
91+ snapshot .Info .Warnings = append (snapshot .Info .Warnings , result .err .Error ())
92+ } else {
93+ snapshot .Info .VendorWarnings [vendor ] = append (snapshot .Info .VendorWarnings [vendor ], result .err .Error ())
94+ }
8195 }
8296 if result .snapshot != nil {
83- for _ , warning := range result .snapshot .Warnings {
84- errs = append (errs , errors .New (warning ))
97+ for key , warnings := range result .snapshot .VendorWarnings {
98+ if len (warnings ) > 0 {
99+ snapshot .Info .VendorWarnings [key ] = append (snapshot .Info .VendorWarnings [key ], warnings ... )
100+ }
101+ }
102+ if vendor != "" && len (result .snapshot .Warnings ) > 0 {
103+ snapshot .Info .VendorWarnings [vendor ] = append (snapshot .Info .VendorWarnings [vendor ], result .snapshot .Warnings ... )
104+ } else {
105+ snapshot .Info .Warnings = append (snapshot .Info .Warnings , result .snapshot .Warnings ... )
85106 }
86107 }
87108 if result .snapshot == nil || len (result .snapshot .Devices ) == 0 {
@@ -100,17 +121,33 @@ func (c Client) Collect(ctx context.Context) (*Snapshot, error) {
100121 xpuVersion = item .DriverVersion
101122 }
102123 }
103- snapshot . Warnings = append (snapshot .Warnings , errs ... )
104- if len ( snapshot . Devices ) == 0 && len ( errs ) > 0 {
105- return nil , fmt . Errorf ( "calling accelerator monitoring tools failed: %w" , errors . Join ( errs ... ) )
124+ warnings : = append ([] string {}, snapshot .Info . Warnings ... )
125+ for _ , vendorWarnings := range snapshot . Info . VendorWarnings {
126+ warnings = append ( warnings , vendorWarnings ... )
106127 }
107-
108- snapshot .Info .CollectedAt = time .Now ()
109- for _ , err := range errs {
110- snapshot .Info .Warnings = append (snapshot .Info .Warnings , err .Error ())
128+ for _ , device := range snapshot .Devices {
129+ if device .ParentID != "" {
130+ continue
131+ }
132+ switch {
133+ case device .GPU != nil :
134+ warnings = append (warnings , device .GPU .Warnings ... )
135+ case device .NPU != nil :
136+ warnings = append (warnings , device .NPU .Warnings ... )
137+ case device .XPU != nil :
138+ warnings = append (warnings , device .XPU .Warnings ... )
139+ }
111140 }
141+ for _ , warning := range warnings {
142+ errs = append (errs , errors .New (warning ))
143+ }
144+ snapshot .Warnings = errs
145+ snapshot .Info .CollectedAt = time .Now ()
112146 snapshot .Info .XPUDriverVersion = xpuVersion
113147 snapshot .Info .Type , snapshot .Info .DriverVersion = mergeProviderMetadata (active )
148+ if len (snapshot .Devices ) == 0 && len (errs ) > 0 {
149+ return snapshot , fmt .Errorf ("calling accelerator monitoring tools failed: %w" , errors .Join (errs ... ))
150+ }
114151 return snapshot , nil
115152}
116153
0 commit comments