MCPcopy
hub / github.com/elastic/go-elasticsearch / main

Function main

_examples/instrumentation/opencensus.go:126–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124}
125
126func 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)

Callers

nothing calls this directly

Calls 15

PrintfMethod · 0.80
CloseMethod · 0.65
WithTimeoutMethod · 0.45
StopMethod · 0.45
UpsertMethod · 0.45
TruncateMethod · 0.45
InfoMethod · 0.45
WithContextMethod · 0.45
FormatMethod · 0.45
IndexMethod · 0.45
HealthMethod · 0.45
WithLevelMethod · 0.45

Tested by

no test coverage detected