-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration to allow users to retry loading dashboards #6560
Changes from 4 commits
c2e42d0
bb9bdb3
87ad410
68d3c51
ee76bc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package dashboards | ||
|
||
import "time" | ||
|
||
type Config struct { | ||
Enabled bool `config:"enabled"` | ||
KibanaIndex string `config:"kibana_index"` | ||
|
@@ -11,11 +13,23 @@ type Config struct { | |
OnlyDashboards bool `config:"only_dashboards"` | ||
OnlyIndex bool `config:"only_index"` | ||
AlwaysKibana bool `config:"always_kibana"` | ||
Retry *Retry `config:"retry"` | ||
} | ||
|
||
type Retry struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type Retry should have comment or be unexported |
||
Enabled bool `config:"enabled"` | ||
Interval time.Duration `config:"interval"` | ||
Maximum uint `config:"maximum"` | ||
} | ||
|
||
var defaultConfig = Config{ | ||
KibanaIndex: ".kibana", | ||
AlwaysKibana: false, | ||
Retry: &Retry{ | ||
Enabled: false, | ||
Interval: time.Second, | ||
Maximum: 0, | ||
}, | ||
} | ||
var ( | ||
defaultDirectory = "kibana" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package dashboards | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
|
@@ -21,13 +23,13 @@ type KibanaLoader struct { | |
msgOutputter MessageOutputter | ||
} | ||
|
||
func NewKibanaLoader(cfg *common.Config, dashboardsConfig *Config, hostname string, msgOutputter MessageOutputter) (*KibanaLoader, error) { | ||
func NewKibanaLoader(ctx context.Context, cfg *common.Config, dashboardsConfig *Config, hostname string, msgOutputter MessageOutputter) (*KibanaLoader, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewKibanaLoader should have comment or be unexported |
||
|
||
if cfg == nil || !cfg.Enabled() { | ||
return nil, fmt.Errorf("Kibana is not configured or enabled") | ||
} | ||
|
||
client, err := kibana.NewKibanaClient(cfg) | ||
client, err := getKibanaClient(ctx, cfg, dashboardsConfig.Retry, 0) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error creating Kibana client: %v", err) | ||
} | ||
|
@@ -45,6 +47,22 @@ func NewKibanaLoader(cfg *common.Config, dashboardsConfig *Config, hostname stri | |
return &loader, nil | ||
} | ||
|
||
func getKibanaClient(ctx context.Context, cfg *common.Config, retryCfg *Retry, retryAttempt uint) (*kibana.Client, error) { | ||
client, err := kibana.NewKibanaClient(cfg) | ||
if err != nil { | ||
if retryCfg.Enabled && (retryCfg.Maximum == 0 || retryCfg.Maximum > retryAttempt) { | ||
select { | ||
case <-ctx.Done(): | ||
return nil, err | ||
case <-time.After(retryCfg.Interval): | ||
return getKibanaClient(ctx, cfg, retryCfg, retryAttempt+1) | ||
} | ||
} | ||
return nil, fmt.Errorf("Error creating Kibana client: %v", err) | ||
} | ||
return client, nil | ||
} | ||
|
||
func (loader KibanaLoader) ImportIndex(file string) error { | ||
params := url.Values{} | ||
params.Set("force", "true") //overwrite the existing dashboards | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,19 @@ NOTE: This setting only works for Kibana 6.0 and newer. | |
|
||
Force loading of dashboards using the Kibana API without querying Elasticsearch for the version | ||
The default is `false`. | ||
|
||
[float] | ||
==== `setup.dashboards.retry.enabled` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the docs. |
||
|
||
If this option is set to true, and Kibana is not reachable at the time when dashboards are loaded, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My comment above made me realise that having a comment about the defaults here would also be great. Some at then of the sentence like. |
||
{beatname_uc} will retry to reconnect to Kibana instead of exiting with an error. | ||
|
||
[float] | ||
==== `setup.dashboards.retry.interval` | ||
|
||
Duration interval between Kibana connection retries. | ||
|
||
[float] | ||
==== `setup.dashboards.retry.maximum` | ||
|
||
Maximum number of retries before exiting with an error. Set to 0 for unlimited retrying. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are default values we normally put them into the reference doc, so here it would be
#setup.dashboards.retry.enabled: false
. Similar for the values below.