| 111 | } |
| 112 | |
| 113 | func newClient(args ClientArgs) (*elastic.Client, error) { |
| 114 | var options []elastic.ClientOptionFunc |
| 115 | |
| 116 | var injected struct { |
| 117 | di.In |
| 118 | |
| 119 | opentracing.Tracer `optional:"true"` |
| 120 | log.Logger |
| 121 | } |
| 122 | |
| 123 | args.Populator.Populate(&injected) |
| 124 | |
| 125 | if injected.Tracer != nil { |
| 126 | options = append(options, |
| 127 | elastic.SetHttpClient( |
| 128 | &http.Client{ |
| 129 | Transport: NewTransport(WithTracer(injected.Tracer)), |
| 130 | }, |
| 131 | ), |
| 132 | ) |
| 133 | } |
| 134 | |
| 135 | if args.Conf.Healthcheck != nil { |
| 136 | options = append(options, elastic.SetHealthcheck(*args.Conf.Healthcheck)) |
| 137 | } |
| 138 | |
| 139 | if args.Conf.Sniff != nil { |
| 140 | options = append(options, elastic.SetSniff(*args.Conf.Sniff)) |
| 141 | } |
| 142 | logger := log.With(injected.Logger, "tag", "es") |
| 143 | options = append(options, |
| 144 | elastic.SetURL(args.Conf.URL...), |
| 145 | elastic.SetBasicAuth(args.Conf.Username, args.Conf.Password), |
| 146 | elastic.SetInfoLog(ElasticLogAdapter{level.Info(logger)}), |
| 147 | elastic.SetErrorLog(ElasticLogAdapter{level.Error(logger)}), |
| 148 | elastic.SetTraceLog(ElasticLogAdapter{level.Debug(logger)}), |
| 149 | ) |
| 150 | client, err := elastic.NewClient(options...) |
| 151 | if err != nil { |
| 152 | client, err = elastic.NewSimpleClient(options...) |
| 153 | if err != nil { |
| 154 | return nil, err |
| 155 | } |
| 156 | } |
| 157 | return client, nil |
| 158 | } |
| 159 | |
| 160 | func provideDefaultClient(maker Maker) (*elastic.Client, error) { |
| 161 | return maker.Make("default") |