Plugins: Add metrics for fs + cloud provisioning info (#111030)
* add new metrics for plugin fs + cloud provisioning * fix test * update label
This commit is contained in:
@@ -72,6 +72,7 @@ type UpdateInfo struct {
|
||||
type FS interface {
|
||||
fs.FS
|
||||
|
||||
Type() string
|
||||
Base() string
|
||||
Files() ([]string, error)
|
||||
Rel(string) (string, error)
|
||||
|
||||
@@ -30,6 +30,10 @@ func NewLocalFS(basePath string) LocalFS {
|
||||
return LocalFS{basePath: basePath}
|
||||
}
|
||||
|
||||
func (f LocalFS) Type() string {
|
||||
return "local"
|
||||
}
|
||||
|
||||
// fileIsAllowed takes an absolute path to a file and an os.FileInfo for that file, and it checks if access to that
|
||||
// file is allowed or not. Access to a file is allowed if the file is in the FS's Base() directory, and if it's a
|
||||
// symbolic link it should not end up outside the plugin's directory.
|
||||
@@ -215,6 +219,10 @@ func NewStaticFS(fs FS) (StaticFS, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f StaticFS) Type() string {
|
||||
return f.FS.Type()
|
||||
}
|
||||
|
||||
// Open checks that name is an allowed file and, if so, it returns a fs.File to access it, by calling the
|
||||
// underlying FS' Open() method.
|
||||
// If access is denied, the function returns ErrFileNotExist.
|
||||
|
||||
@@ -444,6 +444,10 @@ func NewFakePluginFS(base string) *FakePluginFS {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Type() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Open(name string) (fs.File, error) {
|
||||
if f.OpenFunc != nil {
|
||||
return f.OpenFunc(name)
|
||||
|
||||
@@ -345,6 +345,10 @@ func newPathSeparatorOverrideFS(sep string, ufs plugins.FS) (fsPathSeparatorFile
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f fsPathSeparatorFiles) Type() string {
|
||||
return f.FS.Type()
|
||||
}
|
||||
|
||||
// Files returns LocalFS.Files(), but all path separators for the current platform (filepath.Separator)
|
||||
// are replaced with f.separator.
|
||||
func (f fsPathSeparatorFiles) Files() ([]string, error) {
|
||||
|
||||
@@ -456,3 +456,20 @@ type QueryCachingConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
TTLMS int64 `json:"TTLMs"`
|
||||
}
|
||||
|
||||
// CloudProvisioningMethod is the method used to provision the plugin in Grafana Cloud.
|
||||
type CloudProvisioningMethod string
|
||||
|
||||
const (
|
||||
// CloudProvisioningMethodUnknown is used when the plugin provisioning method is unknown.
|
||||
CloudProvisioningMethodUnknown CloudProvisioningMethod = "unknown"
|
||||
|
||||
// CloudProvisioningMethodNone is used when the plugin is not provisioned in Grafana Cloud.
|
||||
CloudProvisioningMethodNone CloudProvisioningMethod = "none"
|
||||
|
||||
// CloudProvisioningMethodURL is used when the plugin is provisioned from a URL.
|
||||
CloudProvisioningMethodURL CloudProvisioningMethod = "url"
|
||||
|
||||
// CloudProvisioningMethodCatalog is used when the plugin is provisioned from the catalog.
|
||||
CloudProvisioningMethodCatalog CloudProvisioningMethod = "catalog"
|
||||
)
|
||||
|
||||
@@ -47,6 +47,10 @@ func (f inMemoryFS) Open(fn string) (fs.File, error) {
|
||||
return &inMemoryFile{path: fn, reader: bytes.NewReader(f.files[fn])}, nil
|
||||
}
|
||||
|
||||
func (f inMemoryFS) Type() string {
|
||||
return "in-memory"
|
||||
}
|
||||
|
||||
// NewFakeFS returns a new FS that always returns ErrFileNotExist when trying to Open() and empty Files().
|
||||
func NewFakeFS() FS {
|
||||
return NewInMemoryFS(nil)
|
||||
|
||||
Reference in New Issue
Block a user