diff --git a/src/query/api/v1/handler/options_test.go b/src/query/api/v1/handler/options_test.go index 3507f36310..fa787c3d7e 100644 --- a/src/query/api/v1/handler/options_test.go +++ b/src/query/api/v1/handler/options_test.go @@ -75,7 +75,10 @@ func TestNewServiceOptions(t *testing.T) { for k, v := range test.headers { h.Add(k, v) } - opts := NewServiceOptions(test.service, h, test.aggOpts) + svcDefaults := ServiceNameAndDefaults{ + ServiceName: test.service, + } + opts := NewServiceOptions(svcDefaults, h, test.aggOpts) assert.Equal(t, test.exp, opts) } } diff --git a/src/query/api/v1/handler/placement/add_test.go b/src/query/api/v1/handler/placement/add_test.go index 5878342e44..42d10ec2e9 100644 --- a/src/query/api/v1/handler/placement/add_test.go +++ b/src/query/api/v1/handler/placement/add_test.go @@ -65,8 +65,11 @@ func TestPlacementAddHandler_Force(t *testing.T) { } require.NotNil(t, req) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } mockPlacementService.EXPECT().AddInstances(gomock.Any()).Return(placement.NewPlacement(), nil, errors.New("no new instances found in the valid zone")) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -83,7 +86,7 @@ func TestPlacementAddHandler_Force(t *testing.T) { require.NotNil(t, req) mockPlacementService.EXPECT().AddInstances(gomock.Not(nil)).Return(placement.NewPlacement(), nil, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, _ = ioutil.ReadAll(resp.Body) @@ -116,7 +119,11 @@ func TestPlacementAddHandler_SafeErr_NoNewInstance(t *testing.T) { } require.NotNil(t, req) - handler.ServeHTTP(serviceName, w, req) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -148,7 +155,11 @@ func TestPlacementAddHandler_SafeErr_NotAllAvailable(t *testing.T) { } require.NotNil(t, req) - handler.ServeHTTP(serviceName, w, req) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -207,7 +218,11 @@ func TestPlacementAddHandler_SafeOK(t *testing.T) { } mockPlacementService.EXPECT().AddInstances(gomock.Any()).Return(nil, nil, errors.New("test err")) - handler.ServeHTTP(serviceName, w, req) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -240,7 +255,7 @@ func TestPlacementAddHandler_SafeOK(t *testing.T) { } else { mockPlacementService.EXPECT().AddInstances(gomock.Any()).Return(existingPlacement.Clone().SetVersion(1), nil, nil) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, _ = ioutil.ReadAll(resp.Body) diff --git a/src/query/api/v1/handler/placement/common_test.go b/src/query/api/v1/handler/placement/common_test.go index 317574319d..457e129fda 100644 --- a/src/query/api/v1/handler/placement/common_test.go +++ b/src/query/api/v1/handler/placement/common_test.go @@ -31,6 +31,7 @@ import ( "github.com/m3db/m3/src/cluster/services" "github.com/m3db/m3/src/cluster/shard" "github.com/m3db/m3/src/query/api/v1/handler" + apihandler "github.com/m3db/m3/src/query/api/v1/handler" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" @@ -52,8 +53,12 @@ func TestPlacementService(t *testing.T) { mockClient.EXPECT().Services(gomock.Not(nil)).Return(mockServices, nil) mockServices.EXPECT().PlacementService(gomock.Not(nil), gomock.Not(nil)).Return(mockPlacementService, nil) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + placementService, algo, err := ServiceWithAlgo( - mockClient, handler.NewServiceOptions(handler.M3DBServiceName, nil, nil), time.Time{}, nil) + mockClient, handler.NewServiceOptions(svcDefaults, nil, nil), time.Time{}, nil) assert.NoError(t, err) assert.NotNil(t, placementService) assert.NotNil(t, algo) @@ -61,7 +66,7 @@ func TestPlacementService(t *testing.T) { // Test Services returns error mockClient.EXPECT().Services(gomock.Not(nil)).Return(nil, errors.New("dummy service error")) placementService, err = Service( - mockClient, handler.NewServiceOptions(handler.M3DBServiceName, nil, nil), time.Time{}, nil) + mockClient, handler.NewServiceOptions(svcDefaults, nil, nil), time.Time{}, nil) assert.Nil(t, placementService) assert.EqualError(t, err, "dummy service error") @@ -69,7 +74,7 @@ func TestPlacementService(t *testing.T) { mockClient.EXPECT().Services(gomock.Not(nil)).Return(mockServices, nil) mockServices.EXPECT().PlacementService(gomock.Not(nil), gomock.Not(nil)).Return(nil, errors.New("dummy placement error")) placementService, err = Service( - mockClient, handler.NewServiceOptions(handler.M3DBServiceName, nil, nil), time.Time{}, nil) + mockClient, handler.NewServiceOptions(svcDefaults, nil, nil), time.Time{}, nil) assert.Nil(t, placementService) assert.EqualError(t, err, "dummy placement error") }) @@ -100,10 +105,13 @@ func TestPlacementServiceWithClusterHeaders(t *testing.T) { }) var ( - serviceValue = handler.M3DBServiceName + serviceValue = handler.M3DBServiceName + svcDefaults = apihandler.ServiceNameAndDefaults{ + ServiceName: handler.M3DBServiceName, + } environmentValue = "bar_env" zoneValue = "baz_zone" - opts = handler.NewServiceOptions(serviceValue, nil, nil) + opts = handler.NewServiceOptions(svcDefaults, nil, nil) ) opts.ServiceEnvironment = environmentValue opts.ServiceZone = zoneValue diff --git a/src/query/api/v1/handler/placement/delete_all_test.go b/src/query/api/v1/handler/placement/delete_all_test.go index eaf30a2640..85333d597a 100644 --- a/src/query/api/v1/handler/placement/delete_all_test.go +++ b/src/query/api/v1/handler/placement/delete_all_test.go @@ -28,6 +28,7 @@ import ( "github.com/m3db/m3/src/cluster/kv" "github.com/m3db/m3/src/cmd/services/m3query/config" + apihandler "github.com/m3db/m3/src/query/api/v1/handler" "github.com/m3db/m3/src/x/instrument" "github.com/golang/mock/gomock" @@ -46,12 +47,16 @@ func TestPlacementDeleteAllHandler(t *testing.T) { require.NoError(t, err) handler := NewDeleteAllHandler(handlerOpts) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + // Test delete success w := httptest.NewRecorder() req := httptest.NewRequest(DeleteAllHTTPMethod, M3DBDeleteAllURL, nil) require.NotNil(t, req) mockPlacementService.EXPECT().Delete() - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() assert.Equal(t, http.StatusOK, resp.StatusCode) @@ -61,7 +66,7 @@ func TestPlacementDeleteAllHandler(t *testing.T) { req = httptest.NewRequest(DeleteAllHTTPMethod, M3DBDeleteAllURL, nil) require.NotNil(t, req) mockPlacementService.EXPECT().Delete().Return(errors.New("error")) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) @@ -71,7 +76,7 @@ func TestPlacementDeleteAllHandler(t *testing.T) { req = httptest.NewRequest(DeleteAllHTTPMethod, M3DBDeleteAllURL, nil) require.NotNil(t, req) mockPlacementService.EXPECT().Delete().Return(kv.ErrNotFound) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() assert.Equal(t, http.StatusNotFound, resp.StatusCode) diff --git a/src/query/api/v1/handler/placement/delete_test.go b/src/query/api/v1/handler/placement/delete_test.go index fa6c0eea71..80dffae277 100644 --- a/src/query/api/v1/handler/placement/delete_test.go +++ b/src/query/api/v1/handler/placement/delete_test.go @@ -50,13 +50,17 @@ func TestPlacementDeleteHandler_Force(t *testing.T) { config.Configuration{}, nil, instrument.NewOptions()) handler := NewDeleteHandler(handlerOpts) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + // Test remove success w := httptest.NewRecorder() req := httptest.NewRequest(DeleteHTTPMethod, "/placement/host1?force=true", nil) req = mux.SetURLVars(req, map[string]string{"id": "host1"}) require.NotNil(t, req) mockPlacementService.EXPECT().RemoveInstances([]string{"host1"}).Return(placement.NewPlacement(), nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, err := ioutil.ReadAll(resp.Body) @@ -70,7 +74,7 @@ func TestPlacementDeleteHandler_Force(t *testing.T) { req = mux.SetURLVars(req, map[string]string{"id": "nope"}) require.NotNil(t, req) mockPlacementService.EXPECT().RemoveInstances([]string{"nope"}).Return(placement.NewPlacement(), errors.New("ID does not exist")) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, err = ioutil.ReadAll(resp.Body) @@ -128,12 +132,16 @@ func testDeleteHandlerSafe(t *testing.T, serviceName string) { SetIsMirrored(true) } + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + req = mux.SetURLVars(req, map[string]string{"id": "host1"}) require.NotNil(t, req) if !isStateless(serviceName) { mockPlacementService.EXPECT().Placement().Return(basePlacement, nil) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, err := ioutil.ReadAll(resp.Body) @@ -165,7 +173,7 @@ func testDeleteHandlerSafe(t *testing.T, serviceName string) { req = mux.SetURLVars(req, map[string]string{"id": "host1"}) require.NotNil(t, req) mockPlacementService.EXPECT().Placement().Return(basePlacement, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, err = ioutil.ReadAll(resp.Body) @@ -259,7 +267,7 @@ func testDeleteHandlerSafe(t *testing.T, serviceName string) { mockPlacementService.EXPECT().CheckAndSet(gomock.Any(), 0).Return(returnPlacement, nil) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, err = ioutil.ReadAll(resp.Body) diff --git a/src/query/api/v1/handler/placement/get_test.go b/src/query/api/v1/handler/placement/get_test.go index 64746732e1..11d37014b7 100644 --- a/src/query/api/v1/handler/placement/get_test.go +++ b/src/query/api/v1/handler/placement/get_test.go @@ -36,6 +36,7 @@ import ( "github.com/m3db/m3/src/cluster/placement/storage" "github.com/m3db/m3/src/cluster/services" "github.com/m3db/m3/src/cmd/services/m3query/config" + apihandler "github.com/m3db/m3/src/query/api/v1/handler" "github.com/m3db/m3/src/x/instrument" "github.com/golang/mock/gomock" @@ -125,8 +126,12 @@ func TestPlacementGetHandler(t *testing.T) { placementObj, err := placement.NewPlacementFromProto(placementProto) require.NoError(t, err) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + mockPlacementService.EXPECT().Placement().Return(placementObj, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -139,7 +144,7 @@ func TestPlacementGetHandler(t *testing.T) { require.NotNil(t, req) mockPlacementService.EXPECT().Placement().Return(nil, errors.New("key not found")) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() assert.Equal(t, http.StatusNotFound, resp.StatusCode) @@ -149,7 +154,7 @@ func TestPlacementGetHandler(t *testing.T) { req = httptest.NewRequest(GetHTTPMethod, "/placement/get?version=foo", nil) require.NotNil(t, req) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() assert.Equal(t, http.StatusBadRequest, resp.StatusCode) @@ -160,7 +165,7 @@ func TestPlacementGetHandler(t *testing.T) { mockPlacementService.EXPECT().PlacementForVersion(12).Return(placementObj.Clone().SetVersion(12), nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, _ = ioutil.ReadAll(resp.Body) assert.Equal(t, http.StatusOK, resp.StatusCode) diff --git a/src/query/api/v1/handler/placement/init_test.go b/src/query/api/v1/handler/placement/init_test.go index c5adc55365..a33c89fa91 100644 --- a/src/query/api/v1/handler/placement/init_test.go +++ b/src/query/api/v1/handler/placement/init_test.go @@ -92,8 +92,12 @@ func TestPlacementInitHandler(t *testing.T) { newPlacement, err := placement.NewPlacementFromProto(initTestPlacementProto) require.NoError(t, err) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + mockPlacementService.EXPECT().BuildInitialPlacement(gomock.Not(nil), 16, 1).Return(newPlacement, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, err := ioutil.ReadAll(resp.Body) require.NoError(t, err) @@ -119,7 +123,7 @@ func TestPlacementInitHandler(t *testing.T) { BuildInitialPlacement(gomock.Not(nil), 64, 2). Return(nil, errors.New("unable to build initial placement")) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, err = ioutil.ReadAll(resp.Body) require.NoError(t, err) @@ -146,7 +150,7 @@ func TestPlacementInitHandler(t *testing.T) { Return(nil, kv.ErrAlreadyExists) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() _, err = ioutil.ReadAll(resp.Body) require.NoError(t, err) diff --git a/src/query/api/v1/handler/placement/replace_test.go b/src/query/api/v1/handler/placement/replace_test.go index f43765ba44..fe80d74399 100644 --- a/src/query/api/v1/handler/placement/replace_test.go +++ b/src/query/api/v1/handler/placement/replace_test.go @@ -82,8 +82,12 @@ func testPlacementReplaceHandlerForce(t *testing.T, serviceName string) { w := httptest.NewRecorder() req := newReplaceRequest(`{"force": true, "leavingInstanceIDs": []}`) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + mockPlacementService.EXPECT().ReplaceInstances([]string{}, gomock.Any()).Return(placement.NewPlacement(), nil, errors.New("test")) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -93,7 +97,7 @@ func testPlacementReplaceHandlerForce(t *testing.T, serviceName string) { w = httptest.NewRecorder() req = newReplaceRequest(`{"force": true, "leavingInstanceIDs": ["a"]}`) mockPlacementService.EXPECT().ReplaceInstances([]string{"a"}, gomock.Not(nil)).Return(placement.NewPlacement(), nil, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp = w.Result() body, _ = ioutil.ReadAll(resp.Body) assert.Equal(t, `{"placement":{"instances":{},"replicaFactor":0,"numShards":0,"isSharded":false,"cutoverTime":"0","isMirrored":false,"maxShardSetId":0},"version":0}`, string(body)) @@ -113,12 +117,16 @@ func testPlacementReplaceHandlerSafeErr(t *testing.T, serviceName string) { w := httptest.NewRecorder() req := newReplaceRequest("{}") + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + mockPlacementService.EXPECT().Placement().Return(newInitPlacement(), nil) if serviceName == apihandler.M3CoordinatorServiceName { mockPlacementService.EXPECT().CheckAndSet(gomock.Any(), 0). Return(newInitPlacement().SetVersion(1), nil) } - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) @@ -238,8 +246,12 @@ func testPlacementReplaceHandlerSafeOk(t *testing.T, serviceName string) { SetInstances(instances). SetVersion(2) + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: serviceName, + } + mockPlacementService.EXPECT().CheckAndSet(matcher, 1).Return(returnPl, nil) - handler.ServeHTTP(serviceName, w, req) + handler.ServeHTTP(svcDefaults, w, req) resp := w.Result() body, _ := ioutil.ReadAll(resp.Body) diff --git a/src/x/debug/debug_test.go b/src/x/debug/debug_test.go index d188195491..f5afbb977f 100644 --- a/src/x/debug/debug_test.go +++ b/src/x/debug/debug_test.go @@ -39,6 +39,7 @@ import ( clusterplacement "github.com/m3db/m3/src/cluster/placement" "github.com/m3db/m3/src/cluster/services" "github.com/m3db/m3/src/cmd/services/m3query/config" + apihandler "github.com/m3db/m3/src/query/api/v1/handler" "github.com/m3db/m3/src/query/api/v1/handler/namespace" "github.com/m3db/m3/src/query/api/v1/handler/placement" "github.com/m3db/m3/src/x/instrument" @@ -273,17 +274,19 @@ func newHandlerOptsAndClient(t *testing.T) (placement.HandlerOptions, *clustercl func TestDefaultSources(t *testing.T) { defaultSources := []string{ - "cpuSource", - "heapSource", - "hostSource", - "goroutineProfile", - "namespaceSource", - "placementSource", + "cpu.prof", + "heap.prof", + "host.json", + "goroutine.prof", + "namespace.json", + "placement-m3db.json", } handlerOpts, mockClient := newHandlerOptsAndClient(t) - - zw, err := NewPlacementAndNamespaceZipWriterWithDefaultSources(1*time.Second, instrument.NewOptions(), mockClient, handlerOpts, []string{"m3db"}) + svcDefaults := []apihandler.ServiceNameAndDefaults{{ + ServiceName: "m3db", + }} + zw, err := NewPlacementAndNamespaceZipWriterWithDefaultSources(1*time.Second, mockClient, handlerOpts, svcDefaults, instrument.NewOptions()) require.NoError(t, err) require.NotNil(t, zw) @@ -292,7 +295,6 @@ func TestDefaultSources(t *testing.T) { iv := reflect.ValueOf(zw).Elem().Interface() z, ok := iv.(zipWriter) require.True(t, ok) - _, ok = z.sources[source] require.True(t, ok) } diff --git a/src/x/debug/namespace_test.go b/src/x/debug/namespace_test.go index 831dbafe2e..0af409aae3 100644 --- a/src/x/debug/namespace_test.go +++ b/src/x/debug/namespace_test.go @@ -33,7 +33,7 @@ import ( func TestNamespaceSource(t *testing.T) { _, mockClient := newHandlerOptsAndClient(t) iOpts := instrument.NewOptions() - n := NewNamespaceInfoSource(iOpts, mockClient) + n := NewNamespaceInfoSource(mockClient, iOpts) buff := bytes.NewBuffer([]byte{}) n.Write(buff, &http.Request{}) diff --git a/src/x/debug/placement_test.go b/src/x/debug/placement_test.go index bb06f51f25..ce121463b2 100644 --- a/src/x/debug/placement_test.go +++ b/src/x/debug/placement_test.go @@ -25,6 +25,7 @@ import ( "net/http" "testing" + apihandler "github.com/m3db/m3/src/query/api/v1/handler" "github.com/m3db/m3/src/x/instrument" "github.com/stretchr/testify/require" @@ -33,7 +34,10 @@ import ( func TestPlacementSource(t *testing.T) { handlerOpts, _ := newHandlerOptsAndClient(t) iOpts := instrument.NewOptions() - p, err := NewPlacementInfoSource(iOpts, handlerOpts, "m3db") + svcDefaults := apihandler.ServiceNameAndDefaults{ + ServiceName: "m3db", + } + p, err := NewPlacementInfoSource(svcDefaults, handlerOpts, iOpts) require.NoError(t, err) buff := bytes.NewBuffer([]byte{})