Skip to content

Commit

Permalink
Add currentOp stub (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilagrow authored Dec 28, 2022
1 parent a80b5a9 commit fed0319
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
19 changes: 19 additions & 0 deletions integration/commands_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,22 @@ func TestCommandsAdministrationServerStatusStress(t *testing.T) {

wg.Wait()
}

func TestCommandsAdministrationCurrentOp(t *testing.T) {
t.Parallel()

s := setup.SetupWithOpts(t, &setup.SetupOpts{
DatabaseName: "admin",
})

var res bson.D
err := s.Collection.Database().RunCommand(s.Ctx,
bson.D{{"currentOp", int32(1)}},
).Decode(&res)
require.NoError(t, err)

doc := ConvertDocument(t, res)

_, ok := must.NotFail(doc.Get("inprog")).(*types.Array)
assert.True(t, ok)
}
36 changes: 36 additions & 0 deletions internal/handlers/common/msg_currentop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

import (
"context"

"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/must"
"github.com/FerretDB/FerretDB/internal/wire"
)

// MsgCurrentOp is a common implementation of currentOp command.
func MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
"inprog", must.NotFail(types.NewArray()),
"ok", float64(1),
))},
}))

return &reply, nil
}
4 changes: 4 additions & 0 deletions internal/handlers/common/msg_listcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ var Commands = map[string]command{
Help: "Creates indexes on a collection.",
Handler: handlers.Interface.MsgCreateIndexes,
},
"currentOp": {
Help: "Returns information about operations currently in progress.",
Handler: handlers.Interface.MsgCurrentOp,
},
"dataSize": {
Help: "Returns the size of the collection in bytes.",
Handler: handlers.Interface.MsgDataSize,
Expand Down
27 changes: 27 additions & 0 deletions internal/handlers/dummy/msg_currentop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dummy

import (
"context"

"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/wire"
)

// MsgCurrentOp implements HandlerInterface.
func (h *Handler) MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
return common.MsgCurrentOp(ctx, msg)
}
3 changes: 3 additions & 0 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Interface interface {
// MsgCreateIndexes creates indexes on a collection.
MsgCreateIndexes(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error)

// MsgCurrentOp returns information about operations currently in progress.
MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error)

// MsgDataSize returns the size of the collection in bytes.
MsgDataSize(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error)

Expand Down
27 changes: 27 additions & 0 deletions internal/handlers/pg/msg_currentop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pg

import (
"context"

"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/wire"
)

// MsgCurrentOp implements HandlerInterface.
func (h *Handler) MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
return common.MsgCurrentOp(ctx, msg)
}
27 changes: 27 additions & 0 deletions internal/handlers/tigris/msg_currentop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tigris

import (
"context"

"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/wire"
)

// MsgCurrentOp implements HandlerInterface.
func (h *Handler) MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
return common.MsgCurrentOp(ctx, msg)
}

1 comment on commit fed0319

@vercel
Copy link

@vercel vercel bot commented on fed0319 Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ferret-db – ./

ferret-db-ferretdb.vercel.app
ferret-db-git-main-ferretdb.vercel.app
ferret-db.vercel.app

Please sign in to comment.