@@ -151,9 +151,13 @@ func NewClient(ctx context.Context, typ PluginType, config Config, opts ...Optio
151151 for _ , opt := range opts {
152152 opt (c )
153153 }
154- if err := c .downloadPlugin (ctx , typ ); err != nil {
154+ assetSource , err := c .downloadPlugin (ctx , typ )
155+ if err != nil {
155156 return nil , err
156157 }
158+ if assetSource != AssetSourceUnknown {
159+ c .metrics .AssetSource = assetSource
160+ }
157161 if ! c .noExec {
158162 if err := c .execPlugin (ctx ); err != nil {
159163 return nil , err
@@ -163,35 +167,36 @@ func NewClient(ctx context.Context, typ PluginType, config Config, opts ...Optio
163167 return c , nil
164168}
165169
166- func (c * Client ) downloadPlugin (ctx context.Context , typ PluginType ) error {
170+ func (c * Client ) downloadPlugin (ctx context.Context , typ PluginType ) ( AssetSource , error ) {
167171 dops := DownloaderOptions {
168172 NoProgress : c .noProgress ,
169173 }
170174 switch c .config .Registry {
171175 case RegistryGrpc :
172- return nil // GRPC plugins are not downloaded
176+ return AssetSourceUnknown , nil // GRPC plugins are not downloaded
173177 case RegistryLocal :
174- return validateLocalExecPath (c .config .Path )
178+ return AssetSourceUnknown , validateLocalExecPath (c .config .Path )
175179 case RegistryGithub :
176180 pathSplit := strings .Split (c .config .Path , "/" )
177181 if len (pathSplit ) != 2 {
178- return fmt .Errorf ("invalid github plugin path: %s. format should be owner/repo" , c .config .Path )
182+ return AssetSourceUnknown , fmt .Errorf ("invalid github plugin path: %s. format should be owner/repo" , c .config .Path )
179183 }
180184 org , name := pathSplit [0 ], pathSplit [1 ]
181185 c .LocalPath = filepath .Join (c .directory , "plugins" , typ .String (), org , name , c .config .Version , "plugin" )
182186 c .LocalPath = WithBinarySuffix (c .LocalPath )
183- return DownloadPluginFromGithub (ctx , c .logger , c .LocalPath , org , name , c .config .Version , typ , dops )
187+ assetSource , err := DownloadPluginFromGithub (ctx , c .logger , c .LocalPath , org , name , c .config .Version , typ , dops )
188+ return assetSource , err
184189 case RegistryDocker :
185190 if imageAvailable , err := isDockerImageAvailable (ctx , c .config .Path ); err != nil {
186- return err
191+ return AssetSourceUnknown , err
187192 } else if ! imageAvailable {
188- return pullDockerImage (ctx , c .config .Path , c .authToken , c .teamName , c .dockerAuth , dops )
193+ return AssetSourceRemote , pullDockerImage (ctx , c .config .Path , c .authToken , c .teamName , c .dockerAuth , dops )
189194 }
190- return nil
195+ return AssetSourceCached , nil
191196 case RegistryCloudQuery :
192197 pathSplit := strings .Split (c .config .Path , "/" )
193198 if len (pathSplit ) != 2 {
194- return fmt .Errorf ("invalid cloudquery plugin path: %s. format should be team/name" , c .config .Path )
199+ return AssetSourceUnknown , fmt .Errorf ("invalid cloudquery plugin path: %s. format should be team/name" , c .config .Path )
195200 }
196201 org , name := pathSplit [0 ], pathSplit [1 ]
197202 c .LocalPath = filepath .Join (c .directory , "plugins" , typ .String (), org , name , c .config .Version , "plugin" )
@@ -208,26 +213,26 @@ func (c *Client) downloadPlugin(ctx context.Context, typ PluginType) error {
208213 }
209214 hubClient , err := getHubClient (c .logger , ops )
210215 if err != nil {
211- return err
216+ return AssetSourceUnknown , err
212217 }
213218 isDocker , err := isDockerPlugin (ctx , hubClient , ops )
214219 if err != nil {
215- return err
220+ return AssetSourceUnknown , err
216221 }
217222 if isDocker {
218223 path := fmt .Sprintf (c .cqDockerHost + "/%s/%s-%s:%s" , ops .PluginTeam , ops .PluginKind , ops .PluginName , ops .PluginVersion )
219224 c .config .Registry = RegistryDocker // will be used by exec step
220225 c .config .Path = path
221226 if imageAvailable , err := isDockerImageAvailable (ctx , path ); err != nil {
222- return err
227+ return AssetSourceUnknown , err
223228 } else if ! imageAvailable {
224- return pullDockerImage (ctx , path , c .authToken , c .teamName , "" , dops )
229+ return AssetSourceRemote , pullDockerImage (ctx , path , c .authToken , c .teamName , "" , dops )
225230 }
226- return nil
231+ return AssetSourceCached , nil
227232 }
228233 return DownloadPluginFromHub (ctx , hubClient , ops , dops )
229234 default :
230- return fmt .Errorf ("unknown registry %s" , c .config .Registry .String ())
235+ return AssetSourceUnknown , fmt .Errorf ("unknown registry %s" , c .config .Registry .String ())
231236 }
232237}
233238
@@ -265,8 +270,9 @@ func (c *Client) ConnectionString() string {
265270
266271func (c * Client ) Metrics () Metrics {
267272 return Metrics {
268- Errors : atomic .LoadUint64 (& c .metrics .Errors ),
269- Warnings : atomic .LoadUint64 (& c .metrics .Warnings ),
273+ Errors : atomic .LoadUint64 (& c .metrics .Errors ),
274+ Warnings : atomic .LoadUint64 (& c .metrics .Warnings ),
275+ AssetSource : c .metrics .AssetSource ,
270276 }
271277}
272278
0 commit comments