MCPcopy
hub / github.com/grafana/tempo / TestInstance_multiTenancy

Function TestInstance_multiTenancy

modules/generator/storage/instance_test.go:108–182  ·  view source on GitHub ↗

Verify multiple instances function next to each other, don't trample over each other and are isolated.

(t *testing.T)

Source from the content-addressed store, hash-verified

106
107// Verify multiple instances function next to each other, don't trample over each other and are isolated.
108func TestInstance_multiTenancy(t *testing.T) {
109 t.Parallel()
110 var err error
111 logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
112
113 mockServer := newMockPrometheusRemoteWriterServer(logger)
114 defer mockServer.close()
115
116 var cfg Config
117 cfg.RegisterFlagsAndApplyDefaults("", nil)
118 cfg.Path = t.TempDir()
119 cfg.RemoteWrite = mockServer.remoteWriteConfig()
120
121 var instances []Storage
122
123 for i := 0; i < 3; i++ {
124 instance, err := New(&cfg, &mockOverrides{}, strconv.Itoa(i), &noopRegisterer{}, logger)
125 assert.NoError(t, err)
126 instances = append(instances, instance)
127 }
128
129 sendCtx, cancel := context.WithCancel(context.Background())
130 defer cancel()
131
132 // Append some data every second
133 go poll(sendCtx, time.Second, func() {
134 for i, instance := range instances {
135 appender := instance.Appender(context.Background())
136
137 lbls := labels.FromMap(map[string]string{"__name__": "my-metric"})
138 _, err := appender.Append(0, lbls, time.Now().UnixMilli(), float64(i))
139 assert.NoError(t, err)
140
141 if sendCtx.Err() != nil {
142 return
143 }
144
145 err = appender.Commit()
146 assert.NoError(t, err)
147 }
148 })
149
150 // Wait until every tenant received at least one request
151 test.Poll(t, 45*time.Second, true, func() interface{} {
152 mockServer.mtx.Lock()
153 defer mockServer.mtx.Unlock()
154
155 for i := range instances {
156 if mockServer.acceptedRequests[strconv.Itoa(i)] == 0 {
157 return false
158 }
159 }
160 return true
161 })
162
163 cancel()
164 for _, instance := range instances {
165 // Shutdown the instance - remote write should flush pending data

Callers

nothing calls this directly

Calls 15

pollFunction · 0.85
remoteWriteConfigMethod · 0.80
GetSamplesMethod · 0.80
NewFunction · 0.70
AppendMethod · 0.65
NowMethod · 0.65
CloseMethod · 0.65
LenMethod · 0.65
closeMethod · 0.45
AppenderMethod · 0.45

Tested by

no test coverage detected