Skip to content

Commit

Permalink
A new metrics scope per plugin is created (flyteorg#393)
Browse files Browse the repository at this point in the history
* A new metrics scope per plugin is created

Signed-off-by: Ketan Umare <[email protected]>

* updated setup context

Signed-off-by: Ketan Umare <[email protected]>

* added unit test

Signed-off-by: Ketan Umare <[email protected]>
  • Loading branch information
kumare3 authored Feb 8, 2022
1 parent f6f4934 commit 6f4475e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/nodes/task/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (t *Handler) Setup(ctx context.Context, sCtx handler.SetupContext) error {
// create a new resource registrar proxy for each plugin, and pass it into the plugin's LoadPlugin() via a setup context
pluginResourceNamespacePrefix := pluginCore.ResourceNamespace(newResourceManagerBuilder.GetID()).CreateSubNamespace(pluginCore.ResourceNamespace(p.ID))
sCtxFinal := newNameSpacedSetupCtx(
tSCtx, newResourceManagerBuilder.GetResourceRegistrar(pluginResourceNamespacePrefix))
tSCtx, newResourceManagerBuilder.GetResourceRegistrar(pluginResourceNamespacePrefix), p.ID)
logger.Infof(ctx, "Loading Plugin [%s] ENABLED", p.ID)
cp, err := pluginCore.LoadPlugin(ctx, sCtxFinal, p)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions pkg/controller/nodes/task/setup_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ func (s setupContext) SecretManager() pluginCore.SecretManager {
return s.secretManager
}

func (s setupContext) MetricsScope() promutils.Scope {
return s.SetupContext.MetricsScope()
}

func (s setupContext) KubeClient() pluginCore.KubeClient {
return s.kubeClient
}
Expand All @@ -44,16 +40,22 @@ func (t *Handler) newSetupContext(sCtx handler.SetupContext) *setupContext {

type nameSpacedSetupCtx struct {
*setupContext
rn pluginCore.ResourceRegistrar
rn pluginCore.ResourceRegistrar
pluginID string
}

func (n nameSpacedSetupCtx) ResourceRegistrar() pluginCore.ResourceRegistrar {
return n.rn
}

func newNameSpacedSetupCtx(sCtx *setupContext, rn pluginCore.ResourceRegistrar) nameSpacedSetupCtx {
func (n nameSpacedSetupCtx) MetricsScope() promutils.Scope {
return n.SetupContext.MetricsScope().NewSubScope(n.pluginID)
}

func newNameSpacedSetupCtx(sCtx *setupContext, rn pluginCore.ResourceRegistrar, pluginID string) nameSpacedSetupCtx {
return nameSpacedSetupCtx{
setupContext: sCtx,
rn: rn,
pluginID: pluginID,
}
}
27 changes: 27 additions & 0 deletions pkg/controller/nodes/task/setup_ctx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package task

import (
"testing"

"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core/mocks"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/handler"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/stretchr/testify/assert"
)

type dummySetupCtx struct {
handler.SetupContext
testScopeName string
}

func (d dummySetupCtx) MetricsScope() promutils.Scope {
return promutils.NewScope(d.testScopeName)
}

func Test_nameSpacedSetupCtx_MetricsScope(t *testing.T) {
r := &mocks.ResourceRegistrar{}
ns := newNameSpacedSetupCtx(&setupContext{SetupContext: &dummySetupCtx{testScopeName: "test-scope-1"}}, r, "p1")
scope := ns.MetricsScope()
assert.NotNil(t, scope)
assert.Equal(t, "test-scope-1:p1:", scope.CurrentScope())
}

0 comments on commit 6f4475e

Please sign in to comment.