-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement index template generation in Golang (#3603)
* Implement index template generation in Golang The index template generation is moved to golang. Changes * Use `go run` to execute command * Template generation is part of libbeat, only execution command is outside as it as has some additional logic on how to read the files. * Add assumption that $ES_BEATS is always a relative path * Add support for more fine grained versioning in template generation * Remove python script as not needed anymore * implement review feedback
- Loading branch information
1 parent
5fa36ad
commit 4e1a173
Showing
15 changed files
with
636 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/template" | ||
) | ||
|
||
// main generates index templates for the beats | ||
func main() { | ||
|
||
beatName := flag.String("beat.name", "", ": Base index name. Normally {beat_name} (required)") | ||
output := flag.String("output", "", "Required: Full path to the output file (required)") | ||
version := flag.String("es.version", beat.GetDefaultVersion(), "Elasticsearch version") | ||
|
||
flag.Parse() | ||
|
||
var existingFiles []string | ||
files := flag.Args() | ||
|
||
if len(files) == 0 { | ||
fmt.Fprintf(os.Stderr, "No fields.yml files provided. At least one file must be added.") | ||
os.Exit(1) | ||
} | ||
|
||
if *beatName == "" { | ||
fmt.Fprintf(os.Stderr, "beat.name is empty. It must be set.") | ||
os.Exit(1) | ||
} | ||
|
||
// Skip some of the passed files, as not all beats have the same files | ||
for _, f := range files { | ||
if _, err := os.Stat(f); err != nil { | ||
fmt.Printf("Skipping file because it does not exist: %s", f) | ||
continue | ||
} | ||
existingFiles = append(existingFiles, f) | ||
} | ||
|
||
// Make it compatible with the sem versioning | ||
if *version == "2x" { | ||
*version = "2.0.0" | ||
} | ||
|
||
templateString, err := template.GetTemplate(*version, *beatName, existingFiles) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error generating template: %+v", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = ioutil.WriteFile(*output, []byte(templateString.StringToPrint()), 0644) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error writing output: %s", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.