-
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
Use import/export API for loading dashboards and index pattern #4413
Conversation
@monicasarbu Should this also go under |
@ruflin This PR is at a very early stage. My plan is to move the import and export functionality to libbeat and then create a script to use it. For now it's just a script (that I will remove) only for testing the import/export API. |
e85f3e2
to
8e271db
Compare
9160e6f
to
a294e57
Compare
0efa466
to
9446eff
Compare
I think we need to add |
@tsg Fixed, thanks! |
libbeat/dashboards/dashboards.go
Outdated
return fmt.Errorf("fail to create the Kibana loader: %v", err) | ||
} | ||
|
||
if kibanaLoader == nil { |
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.
Seems that etiher err == nil
or kibanaLoader != nil
, so I think the second check here is not needed and it doesn't follow our usual error checking pattern.
libbeat/dashboards/kibana_loader.go
Outdated
} | ||
|
||
func (loader KibanaLoader) Close() error { | ||
//return loader.client.Close() |
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.
Seems that there's nothing to do on Close. Then you can just delete the comment, not to confuse future readers.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
logp.Debug("kibana", "Kibana url: %s", kibanaURL) | ||
|
||
client := &Client{ | ||
|
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.
Minor issue, but this extra empty line could be deleted.
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.
fixed
URL: kibanaURL, | ||
http: &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates |
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.
Hmm, does this mean that HTTPS is always enabled? The comment looks like "insecure by default", we have to be careful with this.
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.
This is something that we need to address in the next PR.
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.
Added to the TODO list: #4409
libbeat/dashboards/kibana_loader.go
Outdated
|
||
if cfg == nil { | ||
cfg = common.NewConfig() | ||
err := cfg.SetBool("enabled", -1, true) |
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.
"enabled" is forced to true here, but I didn't see where it's actually checked. We should make sure that disabling with enabled: false
works.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
|
||
kibanaURL, err := common.MakeURL(config.Protocol, config.Path, config.Host, 5601) | ||
if err != nil { | ||
logp.Err("Invalid host param set: %s, Error: %v", config.Host, err) |
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.
We generally avoid logp.Err
immediately followed by returning an error.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
|
||
reqURL, err := addPath(conn.URL, extraPath) | ||
if err != nil { | ||
return 0, nil, fmt.Errorf("fail to parse URL %s: %v", conn.URL, err) |
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.
Would be perhaps better to write the "fail to parse URL" error in the addPath
method?
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.
fixed
libbeat/setup/kibana/client.go
Outdated
|
||
req, err := http.NewRequest(method, reqURL, body) | ||
if err != nil { | ||
logp.Err("Fail to create a HTTP %s request: %v", method, err) |
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.
Return error instead of logging.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
|
||
resp, err := conn.http.Do(req) | ||
if err != nil { | ||
logp.Err("Fail to execute a HTTP %s request: %v", method, err) |
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.
same here.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
|
||
_, result, err := client.Connection.Request("GET", "/api/status", nil, nil) | ||
if err != nil { | ||
return "", fmt.Errorf("HTTP GET request to /api/status fails: %v", err) |
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.
Please add the result
to the error message.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
var kibanaVersion kibanaVersionResponse | ||
err = json.Unmarshal(result, &kibanaVersion) | ||
if err != nil { | ||
return "", fmt.Errorf("fail to unmarshall the HTTP response from Kibana %s: %v", client.Connection.URL, err) |
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.
unmarshal
with one l
.
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.
fixed
libbeat/setup/kibana/client.go
Outdated
if err != nil { | ||
return fmt.Errorf("%v. Response: %s", err, response) | ||
} | ||
if statusCode != 200 { |
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.
200 might be too strict here. Maybe > 300
?
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.
true, fixed
libbeat/dashboards/kibana_loader.go
Outdated
) | ||
|
||
var importAPI = "/api/kibana/dashboards/import" | ||
var exportAPI = "/api/kibana/dashboards/export" |
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.
exportAPI
doesn't seem to be used.
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.
fixed
@@ -305,16 +306,8 @@ index-template: ## @build Generate index templates for the given $VERSION. This | |||
### KIBANA FILES HANDLING ### | |||
ES_URL?=http://localhost:9200 | |||
|
|||
.PHONY: export-dashboards | |||
export-dashboards: python-env update | |||
. ${PYTHON_ENV}/bin/activate && python ${ES_BEATS}/dev-tools/export_dashboards.py --url ${ES_URL} --dir $(shell pwd)/_meta/kibana --regex ${BEAT_NAME}-* |
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.
Could we get export-dashboards
and import-dashboards
targets based on the go code? I'm good with follow up PR for them.
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.
It's a bit tricky for export-dashboards
as we need to pass the list of ids that we want to export in one json file. Usually you would run it to export the dashboards for a module, not for a Beat. Added to the TODO list in the meta issue: #4409
00523db
to
6139a64
Compare
I think it would make sense to add |
e60dafc
to
afaaeeb
Compare
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 we update / improve dashboards for 6.x in the future, will we also update 5.x dashboards? Probably best would be that we "freeze" them as they are and improvements / new features only are available for 6.x?
.gitignore
Outdated
@@ -22,6 +22,9 @@ coverage.out | |||
*.swo | |||
*.swn | |||
|
|||
# Executable |
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.
I would move this to a local ignore file in dashboards
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.
Good idea, done.
auditbeat/auditbeat.reference.yml
Outdated
# Scheme and port can be left out and will be set to the default (http and 5601) | ||
# In case you specify and additional path, the scheme is required: http://localhost:5601/path | ||
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 | ||
# host: "localhost:5601" |
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.
Remove spaces in front of config options for easier uncommenting. Also below.
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.
done!
libbeat/dashboards/dashboards.go
Outdated
} | ||
func getMajorVersion(version string) (int, error) { | ||
|
||
majorVersion := string(version[0]) |
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.
This will break with release 10.*
:-)
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.
done
a5b8147
to
1496049
Compare
@ruflin yes, that's the plan to freeze the 5.x dashboards and improve only the 6.x dashboards. |
218c11b
to
57d4a31
Compare
If the Elasticsearch version is older than 6.x, then the dashboards are loaded directly into Elasticsearch. The old dashboards are moved to the 5.x directory.
c0f1f8b
to
25f5c73
Compare
jenkins, test it |
This is trying to implement #4409.
The Beats 6.x dashboards are different than the Beats 5.x dashboards and are not compatible. Thanks to the Kibana API, we can have a json file for each module instead of multiple json files (for dashboards, visualizations, searches, etc). Thus, the way to import/export dashboards differs from the Kibana version that should be equal to the Elasticsearch version.
The json file containing the index-pattern contain as
version
the Beat version, and the dashboards contain asversion
the Kibana version that exported the dashboards.If Kibana version is 5.x and older:
_meta/kibana/5.x
directoryIf Kibana version is 6.x and greater:
setup.kibana*
settings._meta/kibana/default
directory for each Beat module.In order to make use of the import/export API the following changes are needed:
_meta/kibana/5.x
directoryand create a new directory under
_meta/kibana/default
for the new dashboards and index-pattern that are importable via the Kibana APImake update
Note: The older dashboards are moved to the
_meta/kibana/5.x
directory only for Metricbeat for now.