mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
Add periodic callhome functionality (#14918)
* Add periodic callhome functionality Periodically (every 24hrs by default), fetch callhome information and upload it to SUBNET. New config keys under the `callhome` subsystem: enable - Set to `on` for enabling callhome. Default `off` frequency - Interval between callhome cycles. Default `24h` * Improvements based on review comments - Update `enableCallhome` safely - Rename pctx to ctx - Block during execution of callhome - Store parsed proxy URL in global subnet config - Store callhome URL(s) in constants - Use existing global transport - Pass auth token to subnetPostReq - Use `config.EnableOn` instead of `"on"` * Use atomic package instead of lock * Use uber atomic package * Use `Cancel` instead of `cancel` Co-authored-by: Harshavardhana <harsha@minio.io> Co-authored-by: Harshavardhana <harsha@minio.io> Co-authored-by: Aditya Manthramurthy <donatello@users.noreply.github.com>
This commit is contained in:
65
internal/config/callhome/callhome.go
Normal file
65
internal/config/callhome/callhome.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package callhome
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/internal/config"
|
||||
"github.com/minio/pkg/env"
|
||||
)
|
||||
|
||||
// Callhome related keys
|
||||
const (
|
||||
Enable = "enable"
|
||||
Frequency = "frequency"
|
||||
)
|
||||
|
||||
// DefaultKVS - default KV config for subnet settings
|
||||
var DefaultKVS = config.KVS{
|
||||
config.KV{
|
||||
Key: Enable,
|
||||
Value: "off",
|
||||
},
|
||||
config.KV{
|
||||
Key: Frequency,
|
||||
Value: "24h",
|
||||
},
|
||||
}
|
||||
|
||||
// Config represents the subnet related configuration
|
||||
type Config struct {
|
||||
// Flag indicating whether callhome is enabled.
|
||||
Enable bool `json:"enable"`
|
||||
|
||||
// The interval between callhome cycles
|
||||
Frequency time.Duration `json:"frequency"`
|
||||
}
|
||||
|
||||
// LookupConfig - lookup config and override with valid environment settings if any.
|
||||
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||
if err = config.CheckValidKeys(config.CallhomeSubSys, kvs, DefaultKVS); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
cfg.Enable = env.Get(config.EnvMinIOCallhomeEnable,
|
||||
kvs.GetWithDefault(Enable, DefaultKVS)) == config.EnableOn
|
||||
cfg.Frequency, err = time.ParseDuration(env.Get(config.EnvMinIOCallhomeFrequency,
|
||||
kvs.GetWithDefault(Frequency, DefaultKVS)))
|
||||
return cfg, err
|
||||
}
|
||||
42
internal/config/callhome/help.go
Normal file
42
internal/config/callhome/help.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package callhome
|
||||
|
||||
import "github.com/minio/minio/internal/config"
|
||||
|
||||
var (
|
||||
defaultHelpPostfix = func(key string) string {
|
||||
return config.DefaultHelpPostfix(DefaultKVS, key)
|
||||
}
|
||||
|
||||
// HelpCallhome - provides help for callhome config
|
||||
HelpCallhome = config.HelpKVS{
|
||||
config.HelpKV{
|
||||
Key: Enable,
|
||||
Type: "on|off",
|
||||
Description: "set to enable callhome" + defaultHelpPostfix(Enable),
|
||||
Optional: true,
|
||||
},
|
||||
config.HelpKV{
|
||||
Key: Frequency,
|
||||
Type: "duration",
|
||||
Description: "time duration between callhome cycles e.g. 24h" + defaultHelpPostfix(Frequency),
|
||||
Optional: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -88,6 +88,7 @@ const (
|
||||
ScannerSubSys = "scanner"
|
||||
CrawlerSubSys = "crawler"
|
||||
SubnetSubSys = "subnet"
|
||||
CallhomeSubSys = "callhome"
|
||||
|
||||
// Add new constants here if you add new fields to config.
|
||||
)
|
||||
@@ -161,6 +162,7 @@ var SubSystems = set.CreateStringSet(
|
||||
NotifyRedisSubSys,
|
||||
NotifyWebhookSubSys,
|
||||
SubnetSubSys,
|
||||
CallhomeSubSys,
|
||||
)
|
||||
|
||||
// SubSystemsDynamic - all sub-systems that have dynamic config.
|
||||
@@ -170,6 +172,7 @@ var SubSystemsDynamic = set.CreateStringSet(
|
||||
ScannerSubSys,
|
||||
HealSubSys,
|
||||
SubnetSubSys,
|
||||
CallhomeSubSys,
|
||||
LoggerWebhookSubSys,
|
||||
AuditWebhookSubSys,
|
||||
AuditKafkaSubSys,
|
||||
|
||||
@@ -53,9 +53,13 @@ const (
|
||||
EnvSiteName = "MINIO_SITE_NAME"
|
||||
EnvSiteRegion = "MINIO_SITE_REGION"
|
||||
|
||||
EnvMinIOSubnetLicense = "MINIO_SUBNET_LICENSE" // Deprecated Dec 2021
|
||||
EnvMinIOSubnetAPIKey = "MINIO_SUBNET_API_KEY"
|
||||
EnvMinIOSubnetProxy = "MINIO_SUBNET_PROXY"
|
||||
EnvMinIOSubnetLicense = "MINIO_SUBNET_LICENSE" // Deprecated Dec 2021
|
||||
EnvMinIOSubnetAPIKey = "MINIO_SUBNET_API_KEY"
|
||||
EnvMinIOSubnetProxy = "MINIO_SUBNET_PROXY"
|
||||
|
||||
EnvMinIOCallhomeEnable = "MINIO_CALLHOME_ENABLE"
|
||||
EnvMinIOCallhomeFrequency = "MINIO_CALLHOME_FREQUENCY"
|
||||
|
||||
EnvMinIOServerURL = "MINIO_SERVER_URL"
|
||||
EnvMinIOBrowserRedirectURL = "MINIO_BROWSER_REDIRECT_URL"
|
||||
EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE"
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
package subnet
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/minio/minio/internal/config"
|
||||
"github.com/minio/pkg/env"
|
||||
xnet "github.com/minio/pkg/net"
|
||||
)
|
||||
|
||||
// DefaultKVS - default KV config for subnet settings
|
||||
@@ -49,7 +48,7 @@ type Config struct {
|
||||
APIKey string `json:"api_key"`
|
||||
|
||||
// The HTTP(S) proxy URL to use for connecting to SUBNET
|
||||
Proxy string `json:"proxy"`
|
||||
ProxyURL *xnet.URL `json:"proxy_url"`
|
||||
}
|
||||
|
||||
// LookupConfig - lookup config and override with valid environment settings if any.
|
||||
@@ -58,10 +57,12 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
cfg.Proxy = env.Get(config.EnvMinIOSubnetProxy, kvs.Get(config.Proxy))
|
||||
_, err = url.Parse(cfg.Proxy)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
proxy := env.Get(config.EnvMinIOSubnetProxy, kvs.Get(config.Proxy))
|
||||
if len(proxy) > 0 {
|
||||
cfg.ProxyURL, err = xnet.ParseHTTPURL(proxy)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
|
||||
cfg.License = env.Get(config.EnvMinIOSubnetLicense, kvs.Get(config.License))
|
||||
|
||||
Reference in New Issue
Block a user