@@ -28,6 +28,7 @@ import (
2828 "time"
2929
3030 "github.com/gorilla/handlers"
31+ "github.com/olivere/elastic/v7"
3132 log "github.com/sirupsen/logrus"
3233 "github.com/spf13/pflag"
3334 "github.com/spf13/viper"
@@ -69,6 +70,7 @@ func init() {
6970 pflag .String ("auth_connector_name" , "" , "If any, the name of the auth connector to be used with Pixie" )
7071 pflag .String ("auth_connector_callback_url" , "" , "If any, the callback URL for the auth connector" )
7172 pflag .Bool ("script_modification_disabled" , false , "If script modification should be disallowed to prevent arbitrary script execution" )
73+ pflag .Bool ("disable_autocomplete" , false , "Disable autocomplete functionality (no Elasticsearch required)" )
7274}
7375
7476func main () {
@@ -136,15 +138,20 @@ func main() {
136138 // Connect to NATS.
137139 nc := msgbus .MustConnectNATS ()
138140
139- esConfig := & esutils.Config {
140- URL : []string {viper .GetString ("elastic_service" )},
141- User : viper .GetString ("elastic_username" ),
142- Passwd : viper .GetString ("elastic_password" ),
143- CaCertFile : viper .GetString ("elastic_ca_cert" ),
144- }
145- es , err := esutils .NewEsClient (esConfig )
146- if err != nil {
147- log .WithError (err ).Fatal ("Could not connect to elastic" )
141+ disableAutocomplete := viper .GetBool ("disable_autocomplete" )
142+
143+ var es * elastic.Client
144+ if ! disableAutocomplete {
145+ esConfig := & esutils.Config {
146+ URL : []string {viper .GetString ("elastic_service" )},
147+ User : viper .GetString ("elastic_username" ),
148+ Passwd : viper .GetString ("elastic_password" ),
149+ CaCertFile : viper .GetString ("elastic_ca_cert" ),
150+ }
151+ es , err = esutils .NewEsClient (esConfig )
152+ if err != nil {
153+ log .WithError (err ).Fatal ("Could not connect to elastic" )
154+ }
148155 }
149156
150157 mux := http .NewServeMux ()
@@ -228,45 +235,52 @@ func main() {
228235 vizierpb .RegisterVizierServiceServer (s .GRPCServer (), vpt )
229236 vizierpb .RegisterVizierDebugServiceServer (s .GRPCServer (), vpt )
230237
231- mdIndexName := viper .GetString ("md_index_name" )
232- if mdIndexName == "" {
233- log .Fatal ("Must specify a name for the elastic index." )
234- }
235- esSuggester , err := autocomplete .NewElasticSuggester (es , mdIndexName , "scripts" , pc )
236- if err != nil {
237- log .WithError (err ).Fatal ("Failed to start elastic suggester" )
238- }
239-
240- var br * script.BundleManager
241- var bundleErr error
242- updateBundle := func () {
243- // Requiring the bundle manager in the API service is temporary until we
244- // start indexing scripts.
245- br , bundleErr = script .NewBundleManagerWithOrg ([]string {defaultBundleFile , ossBundleFile }, "" , "" )
246- if bundleErr != nil {
247- log .WithError (bundleErr ).Error ("Failed to init bundle manager" )
248- br = nil
238+ var suggester autocomplete.Suggester
239+ if disableAutocomplete {
240+ log .Info ("Autocomplete disabled - using NoopSuggester" )
241+ suggester = autocomplete .NewNoopSuggester ()
242+ } else {
243+ mdIndexName := viper .GetString ("md_index_name" )
244+ if mdIndexName == "" {
245+ log .Fatal ("Must specify a name for the elastic index." )
249246 }
250- esSuggester .UpdateScriptBundle (br )
251- }
252-
253- quitCh := make (chan bool )
254- go func () {
255- updateBundle ()
256- scriptTimer := time .NewTicker (30 * time .Second )
257- defer scriptTimer .Stop ()
258- for {
259- select {
260- case <- quitCh :
261- return
262- case <- scriptTimer .C :
263- updateBundle ()
247+ esSuggester , err := autocomplete .NewElasticSuggester (es , mdIndexName , "scripts" , pc )
248+ if err != nil {
249+ log .WithError (err ).Fatal ("Failed to start elastic suggester" )
250+ }
251+ suggester = esSuggester
252+
253+ var br * script.BundleManager
254+ var bundleErr error
255+ updateBundle := func () {
256+ // Requiring the bundle manager in the API service is temporary until we
257+ // start indexing scripts.
258+ br , bundleErr = script .NewBundleManagerWithOrg ([]string {defaultBundleFile , ossBundleFile }, "" , "" )
259+ if bundleErr != nil {
260+ log .WithError (bundleErr ).Error ("Failed to init bundle manager" )
261+ br = nil
264262 }
263+ esSuggester .UpdateScriptBundle (br )
265264 }
266- }()
267- defer close (quitCh )
268265
269- as := & controllers.AutocompleteServer {Suggester : esSuggester }
266+ quitCh := make (chan bool )
267+ go func () {
268+ updateBundle ()
269+ scriptTimer := time .NewTicker (30 * time .Second )
270+ defer scriptTimer .Stop ()
271+ for {
272+ select {
273+ case <- quitCh :
274+ return
275+ case <- scriptTimer .C :
276+ updateBundle ()
277+ }
278+ }
279+ }()
280+ defer close (quitCh )
281+ }
282+
283+ as := & controllers.AutocompleteServer {Suggester : suggester }
270284 cloudpb .RegisterAutocompleteServiceServer (s .GRPCServer (), as )
271285
272286 os := & controllers.OrganizationServiceServer {ProfileServiceClient : pc , AuthServiceClient : ac , OrgServiceClient : oc }
0 commit comments