()
| 124 | } |
| 125 | |
| 126 | func main() { |
| 127 | log.SetFlags(0) |
| 128 | start := time.Now() |
| 129 | |
| 130 | // Create new elasticsearch client ... |
| 131 | // |
| 132 | es, err := elasticsearch.New( |
| 133 | // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 134 | // ... using the "ochttp" wrapper for instrumentation |
| 135 | elasticsearch.WithTransportOptions(elastictransport.WithTransport(&ochttp.Transport{})), |
| 136 | // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 137 | ) |
| 138 | if err != nil { |
| 139 | log.Fatalf("ERROR: %s", err) |
| 140 | } |
| 141 | defer func() { |
| 142 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 143 | defer cancel() |
| 144 | if err := es.Close(ctx); err != nil { |
| 145 | fmt.Printf("Error closing the client: %s\n", err) |
| 146 | } |
| 147 | }() |
| 148 | |
| 149 | // Set up the "done" channel |
| 150 | // |
| 151 | done := make(chan os.Signal) |
| 152 | signal.Notify(done, os.Interrupt) |
| 153 | |
| 154 | // Set up tickers |
| 155 | // |
| 156 | tickers := struct { |
| 157 | Info *time.Ticker |
| 158 | Index *time.Ticker |
| 159 | Health *time.Ticker |
| 160 | Search *time.Ticker |
| 161 | }{ |
| 162 | Info: time.NewTicker(time.Second), |
| 163 | Index: time.NewTicker(500 * time.Millisecond), |
| 164 | Health: time.NewTicker(5 * time.Second), |
| 165 | Search: time.NewTicker(10 * time.Second), |
| 166 | } |
| 167 | defer tickers.Info.Stop() |
| 168 | defer tickers.Index.Stop() |
| 169 | defer tickers.Health.Stop() |
| 170 | defer tickers.Search.Stop() |
| 171 | |
| 172 | // Register views bundled with the "ochttp" plugin |
| 173 | // |
| 174 | if err := view.Register( |
| 175 | ochttp.ClientRoundtripLatencyDistribution, |
| 176 | ochttp.ClientCompletedCount, |
| 177 | ); err != nil { |
| 178 | log.Fatalf("ERROR: %s", err) |
| 179 | } |
| 180 | |
| 181 | // Report views to STDOUT once in a while |
| 182 | // |
| 183 | view.SetReportingPeriod(5 * time.Second) |
nothing calls this directly
no test coverage detected