@@ -19,9 +19,11 @@ const createDataStreamLongDescription = `Use this command to create a new data s
1919The command can extend the package with a new data stream using embedded data stream template and wizard.`
2020
2121type newDataStreamAnswers struct {
22- Name string
23- Title string
24- Type string
22+ Name string
23+ Title string
24+ Type string
25+ SyntheticAndTimeSeries bool
26+ Synthetic bool
2527}
2628
2729func createDataStreamCommandAction (cmd * cobra.Command , args []string ) error {
@@ -68,6 +70,40 @@ func createDataStreamCommandAction(cmd *cobra.Command, args []string) error {
6870 return errors .Wrap (err , "prompt failed" )
6971 }
7072
73+ if answers .Type == "metrics" {
74+ qs := []* survey.Question {
75+ {
76+ Name : "syntheticAndTimeSeries" ,
77+ Prompt : & survey.Confirm {
78+ Message : "Enable time series and synthetic source?" ,
79+ Default : true ,
80+ },
81+ Validate : survey .Required ,
82+ },
83+ }
84+ err = survey .Ask (qs , & answers )
85+ if err != nil {
86+ return errors .Wrap (err , "prompt failed" )
87+ }
88+
89+ if ! answers .SyntheticAndTimeSeries {
90+ qs := []* survey.Question {
91+ {
92+ Name : "synthetic" ,
93+ Prompt : & survey.Confirm {
94+ Message : "Enable synthetic source?" ,
95+ Default : true ,
96+ },
97+ Validate : survey .Required ,
98+ },
99+ }
100+ err = survey .Ask (qs , & answers )
101+ if err != nil {
102+ return errors .Wrap (err , "prompt failed" )
103+ }
104+ }
105+ }
106+
71107 descriptor := createDataStreamDescriptorFromAnswers (answers , packageRoot )
72108 err = archetype .CreateDataStream (descriptor )
73109 if err != nil {
@@ -79,12 +115,27 @@ func createDataStreamCommandAction(cmd *cobra.Command, args []string) error {
79115}
80116
81117func createDataStreamDescriptorFromAnswers (answers newDataStreamAnswers , packageRoot string ) archetype.DataStreamDescriptor {
118+ manifest := packages.DataStreamManifest {
119+ Name : answers .Name ,
120+ Title : answers .Title ,
121+ Type : answers .Type ,
122+ }
123+
124+ if ! answers .SyntheticAndTimeSeries && ! answers .Synthetic {
125+ return archetype.DataStreamDescriptor {
126+ Manifest : manifest ,
127+ PackageRoot : packageRoot ,
128+ }
129+ }
130+ elasticsearch := packages.Elasticsearch {
131+ SourceMode : "synthetic" ,
132+ }
133+ if answers .SyntheticAndTimeSeries {
134+ elasticsearch .IndexMode = "time_series"
135+ }
136+ manifest .Elasticsearch = & elasticsearch
82137 return archetype.DataStreamDescriptor {
83- Manifest : packages.DataStreamManifest {
84- Name : answers .Name ,
85- Title : answers .Title ,
86- Type : answers .Type ,
87- },
138+ Manifest : manifest ,
88139 PackageRoot : packageRoot ,
89140 }
90141}
0 commit comments