Skip to content

Commit

Permalink
having single struct for both metrics
Browse files Browse the repository at this point in the history
Signed-off-by: sethiyash <yashsethiya97@gmail.com>
  • Loading branch information
sethiyash committed Dec 21, 2023
1 parent c871303 commit 0174469
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 111 deletions.
35 changes: 17 additions & 18 deletions cmd/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,14 @@ func Run(opts Options, runLog logr.Logger) error {
}
{ // add controller for apps
appFactory := app.CRDAppFactory{
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
CountMetrics: countMetrics,
ReconcileTimeMetrics: reconcileTimeMetrics,
CmdRunner: sidecarCmdExec,
Kubeconf: kubeconf,
CompInfo: compInfo,
CacheFolder: cacheFolderApps,
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
AppMetrics: &metrics.Metrics{ReconcileCountMetrics: countMetrics, ReconcileTimeMetrics: reconcileTimeMetrics},
CmdRunner: sidecarCmdExec,
Kubeconf: kubeconf,
CompInfo: compInfo,
CacheFolder: cacheFolderApps,
}
reconciler := app.NewReconciler(kcClient, runLog.WithName("app"),
appFactory, refTracker, updateStatusTracker, compInfo)
Expand All @@ -232,7 +231,8 @@ func Run(opts Options, runLog logr.Logger) error {
kcClient, opts.PackagingGlobalNS, runLog.WithName("handler"))

reconciler := pkginstall.NewReconciler(kcClient, pkgClient, coreClient, pkgToPkgInstallHandler,
runLog.WithName("pkgi"), compInfo, kcConfig, countMetrics, reconcileTimeMetrics)
runLog.WithName("pkgi"), compInfo, kcConfig, &metrics.Metrics{ReconcileCountMetrics: countMetrics,
ReconcileTimeMetrics: reconcileTimeMetrics})

ctrl, err := controller.New("pkgi", mgr, controller.Options{
Reconciler: reconciler,
Expand All @@ -256,14 +256,13 @@ func Run(opts Options, runLog logr.Logger) error {

{ // add controller for pkgrepositories
appFactory := pkgrepository.AppFactory{
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
CountMetrics: countMetrics,
TimeMetrics: reconcileTimeMetrics,
CmdRunner: sidecarCmdExec,
Kubeconf: kubeconf,
CacheFolder: cacheFolderPkgRepoApps,
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
AppMetrics: &metrics.Metrics{ReconcileCountMetrics: countMetrics, ReconcileTimeMetrics: reconcileTimeMetrics},
CmdRunner: sidecarCmdExec,
Kubeconf: kubeconf,
CacheFolder: cacheFolderPkgRepoApps,
}

reconciler := pkgrepository.NewReconciler(kcClient, coreClient,
Expand Down
11 changes: 5 additions & 6 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ type App struct {
memoizedKubernetesVersion string
memoizedKubernetesAPIs []string

log logr.Logger
opts Opts
countMetrics *metrics.ReconcileCountMetrics
timeMetrics *metrics.ReconcileTimeMetrics
log logr.Logger
opts Opts
appMetrics *metrics.Metrics

isFirstReconcile bool
pendingStatusUpdate bool
Expand All @@ -68,11 +67,11 @@ type App struct {

func NewApp(app v1alpha1.App, hooks Hooks,
fetchFactory fetch.Factory, templateFactory template.Factory,
deployFactory deploy.Factory, log logr.Logger, opts Opts, appMetrics *metrics.ReconcileCountMetrics, timeMetrics *metrics.ReconcileTimeMetrics, compInfo ComponentInfo) *App {
deployFactory deploy.Factory, log logr.Logger, opts Opts, appMetrics *metrics.Metrics, compInfo ComponentInfo) *App {

return &App{app: app, appPrev: *(app.DeepCopy()), hooks: hooks,
fetchFactory: fetchFactory, templateFactory: templateFactory,
deployFactory: deployFactory, log: log, opts: opts, countMetrics: appMetrics, timeMetrics: timeMetrics, compInfo: compInfo}
deployFactory: deployFactory, log: log, opts: opts, appMetrics: appMetrics, compInfo: compInfo}
}

func (a *App) Name() string { return a.app.Name }
Expand Down
25 changes: 12 additions & 13 deletions pkg/app/app_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ import (

// CRDAppFactory allows to create CRDApps.
type CRDAppFactory struct {
CoreClient kubernetes.Interface
AppClient kcclient.Interface
KcConfig *config.Config
CountMetrics *metrics.ReconcileCountMetrics
ReconcileTimeMetrics *metrics.ReconcileTimeMetrics
VendirConfigHook func(vendirconf.Config) vendirconf.Config
KbldAllowBuild bool
CmdRunner exec.CmdRunner
Kubeconf *kubeconfig.Kubeconfig
CompInfo ComponentInfo
DeployFactory deploy.Factory
CacheFolder *memdir.TmpDir
CoreClient kubernetes.Interface
AppClient kcclient.Interface
KcConfig *config.Config
AppMetrics *metrics.Metrics
VendirConfigHook func(vendirconf.Config) vendirconf.Config
KbldAllowBuild bool
CmdRunner exec.CmdRunner
Kubeconf *kubeconfig.Kubeconfig
CompInfo ComponentInfo
DeployFactory deploy.Factory
CacheFolder *memdir.TmpDir
}

// NewCRDApp creates a CRDApp injecting necessary dependencies.
Expand All @@ -49,7 +48,7 @@ func (f *CRDAppFactory) NewCRDApp(app *kcv1alpha1.App, log logr.Logger) *CRDApp
templateFactory := template.NewFactory(f.CoreClient, fetchFactory, f.KbldAllowBuild, f.CmdRunner)
deployFactory := deploy.NewFactory(f.CoreClient, f.Kubeconf, f.KcConfig, f.CmdRunner, log)

return NewCRDApp(app, log, f.CountMetrics, f.ReconcileTimeMetrics, f.AppClient, fetchFactory, templateFactory, deployFactory, f.CompInfo, Opts{
return NewCRDApp(app, log, f.AppMetrics, f.AppClient, fetchFactory, templateFactory, deployFactory, f.CompInfo, Opts{
DefaultSyncPeriod: f.KcConfig.AppDefaultSyncPeriod(),
MinimumSyncPeriod: f.KcConfig.AppMinimumSyncPeriod(),
})
Expand Down
24 changes: 12 additions & 12 deletions pkg/app/app_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (a *App) Reconcile(force bool) (reconcile.Result, error) {

var err error

a.countMetrics.InitMetrics(appResourceType, a.Name(), a.Namespace())
a.appMetrics.ReconcileCountMetrics.InitMetrics(appResourceType, a.Name(), a.Namespace())

timerOpts := ReconcileTimerOpts{
DefaultSyncPeriod: a.opts.DefaultSyncPeriod,
Expand Down Expand Up @@ -106,9 +106,9 @@ func (a *App) reconcileDeploy() error {

func (a *App) reconcileFetchTemplateDeploy() exec.CmdRunResult {
reconcileStartTime := time.Now()
a.isFirstReconcile = a.countMetrics.GetReconcileAttemptCounterValue("app", a.app.Name, a.app.Namespace) == 1
a.isFirstReconcile = a.appMetrics.ReconcileCountMetrics.GetReconcileAttemptCounterValue("app", a.app.Name, a.app.Namespace) == 1
defer func() {
a.timeMetrics.RegisterOverallTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.appMetrics.ReconcileTimeMetrics.RegisterOverallTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
time.Since(reconcileStartTime))
}()

Expand Down Expand Up @@ -138,7 +138,7 @@ func (a *App) reconcileFetchTemplateDeploy() exec.CmdRunResult {
UpdatedAt: metav1.NewTime(time.Now().UTC()),
}

a.timeMetrics.RegisterFetchTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.appMetrics.ReconcileTimeMetrics.RegisterFetchTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.app.Status.Fetch.UpdatedAt.Sub(a.app.Status.Fetch.StartedAt.Time))

err := a.updateStatus("marking fetch completed")
Expand All @@ -162,7 +162,7 @@ func (a *App) reconcileFetchTemplateDeploy() exec.CmdRunResult {
UpdatedAt: metav1.NewTime(time.Now().UTC()),
}

a.timeMetrics.RegisterTemplateTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.appMetrics.ReconcileTimeMetrics.RegisterTemplateTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.app.Status.Template.UpdatedAt.Sub(templateStartTime))

err = a.updateStatus("marking template completed")
Expand Down Expand Up @@ -213,7 +213,7 @@ func (a *App) updateLastDeploy(result exec.CmdRunResult) exec.CmdRunResult {
},
}

a.timeMetrics.RegisterDeployTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.appMetrics.ReconcileTimeMetrics.RegisterDeployTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
a.Status().Deploy.UpdatedAt.Sub(a.Status().Deploy.StartedAt.Time))

return result
Expand Down Expand Up @@ -267,7 +267,7 @@ func (a *App) setReconciling() {
Status: corev1.ConditionTrue,
})

a.countMetrics.RegisterReconcileAttempt(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.RegisterReconcileAttempt(appResourceType, a.app.Name, a.app.Namespace)
a.app.Status.FriendlyDescription = "Reconciling"
}

Expand All @@ -283,7 +283,7 @@ func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
a.app.Status.ConsecutiveReconcileFailures++
a.app.Status.ConsecutiveReconcileSuccesses = 0
a.app.Status.FriendlyDescription = fmt.Sprintf("Reconcile failed: %s", result.ErrorStr())
a.countMetrics.RegisterReconcileFailure(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.RegisterReconcileFailure(appResourceType, a.app.Name, a.app.Namespace)
a.setUsefulErrorMessage(result)
} else {
a.app.Status.Conditions = append(a.app.Status.Conditions, v1alpha1.Condition{
Expand All @@ -294,7 +294,7 @@ func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
a.app.Status.ConsecutiveReconcileSuccesses++
a.app.Status.ConsecutiveReconcileFailures = 0
a.app.Status.FriendlyDescription = "Reconcile succeeded"
a.countMetrics.RegisterReconcileSuccess(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.RegisterReconcileSuccess(appResourceType, a.app.Name, a.app.Namespace)
a.app.Status.UsefulErrorMessage = ""
}
}
Expand All @@ -307,7 +307,7 @@ func (a *App) setDeleting() {
Status: corev1.ConditionTrue,
})

a.countMetrics.RegisterReconcileDeleteAttempt(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.RegisterReconcileDeleteAttempt(appResourceType, a.app.Name, a.app.Namespace)
a.app.Status.FriendlyDescription = "Deleting"
}

Expand All @@ -323,10 +323,10 @@ func (a *App) setDeleteCompleted(result exec.CmdRunResult) {
a.app.Status.ConsecutiveReconcileFailures++
a.app.Status.ConsecutiveReconcileSuccesses = 0
a.app.Status.FriendlyDescription = fmt.Sprintf("Delete failed: %s", result.ErrorStr())
a.countMetrics.RegisterReconcileDeleteFailed(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.RegisterReconcileDeleteFailed(appResourceType, a.app.Name, a.app.Namespace)
a.setUsefulErrorMessage(result)
} else {
a.countMetrics.DeleteMetrics(appResourceType, a.app.Name, a.app.Namespace)
a.appMetrics.ReconcileCountMetrics.DeleteMetrics(appResourceType, a.app.Name, a.app.Namespace)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/app/app_reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Test_NoInspectReconcile_IfNoDeployAttempted(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

crdApp := NewCRDApp(&app, log, appMetrics, timeMetrics, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
crdApp := NewCRDApp(&app, log, &metrics.Metrics{ReconcileCountMetrics: appMetrics, ReconcileTimeMetrics: timeMetrics}, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
_, err := crdApp.Reconcile(false)
assert.Nil(t, err, "unexpected error with reconciling", err)

Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_NoInspectReconcile_IfInspectNotEnabled(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

crdApp := NewCRDApp(&app, log, appMetrics, timeMetrics, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
crdApp := NewCRDApp(&app, log, &metrics.Metrics{ReconcileCountMetrics: appMetrics, ReconcileTimeMetrics: timeMetrics}, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
_, err := crdApp.Reconcile(false)
assert.Nil(t, err, "unexpected error with reconciling", err)

Expand Down Expand Up @@ -200,7 +200,7 @@ func Test_TemplateError_DisplayedInStatus_UsefulErrorMessageProperty(t *testing.
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

crdApp := NewCRDApp(&app, log, appMetrics, timeMetrics, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
crdApp := NewCRDApp(&app, log, &metrics.Metrics{ReconcileCountMetrics: appMetrics, ReconcileTimeMetrics: timeMetrics}, kappcs, fetchFac, tmpFac, deployFac, FakeComponentInfo{}, Opts{MinimumSyncPeriod: 30 * time.Second})
_, err := crdApp.Reconcile(false)
assert.Nil(t, err, "Unexpected error with reconciling", err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Test_BuildAdditionalDownwardAPIValues_MemoizedCallCount(t *testing.T) {
K8sAPIsCount: &k8sAPIsCallCount,
KCVersionCount: &kcVersionCallCount,
}
app := NewApp(appEmpty, Hooks{}, fetchFac, tmpFac, deployFac, log, Opts{}, metrics.NewCountMetrics(), metrics.NewReconcileTimeMetrics(), fakeInfo)
app := NewApp(appEmpty, Hooks{}, fetchFac, tmpFac, deployFac, log, Opts{}, &metrics.Metrics{}, fakeInfo)

dir, err := os.MkdirTemp("", "temp")
assert.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/exec"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/fetch"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/kubeconfig"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/metrics"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/reftracker"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/template"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -64,7 +65,7 @@ func Test_SecretRefs_RetrievesAllSecretRefs(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

app := apppkg.NewApp(appWithRefs, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, nil, nil, FakeComponentInfo{})
app := apppkg.NewApp(appWithRefs, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, &metrics.Metrics{}, FakeComponentInfo{})

out := app.SecretRefs()
assert.Truef(t, reflect.DeepEqual(out, expected), "Expected: %s\nGot: %s\n", expected, out)
Expand All @@ -88,7 +89,7 @@ func Test_SecretRefs_RetrievesNoSecretRefs_WhenNonePresent(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

app := apppkg.NewApp(appEmpty, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, nil, nil, FakeComponentInfo{})
app := apppkg.NewApp(appEmpty, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, &metrics.Metrics{}, FakeComponentInfo{})

out := app.SecretRefs()
assert.Equal(t, 0, len(out), "No SecretRefs to be returned")
Expand Down Expand Up @@ -126,7 +127,7 @@ func Test_ConfigMapRefs_RetrievesAllConfigMapRefs(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

app := apppkg.NewApp(appWithRefs, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, nil, nil, FakeComponentInfo{})
app := apppkg.NewApp(appWithRefs, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, &metrics.Metrics{}, FakeComponentInfo{})

out := app.ConfigMapRefs()
assert.Truef(t, reflect.DeepEqual(out, expected), "Expected: %s\nGot: %s\n", expected, out)
Expand All @@ -150,7 +151,7 @@ func Test_ConfigMapRefs_RetrievesNoConfigMapRefs_WhenNonePresent(t *testing.T) {
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)

app := apppkg.NewApp(appEmpty, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, nil, nil, FakeComponentInfo{})
app := apppkg.NewApp(appEmpty, apppkg.Hooks{}, fetchFac, tmpFac, deployFac, log, apppkg.Opts{}, &metrics.Metrics{}, FakeComponentInfo{})

out := app.ConfigMapRefs()
assert.Lenf(t, out, 0, "Expected: %s\nGot: %s\n", "No ConfigMapRefs to be returned", out)
Expand Down
7 changes: 3 additions & 4 deletions pkg/app/crd_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ type CRDApp struct {
}

// NewCRDApp creates new CRD app
func NewCRDApp(appModel *kcv1alpha1.App, log logr.Logger, appMetrics *metrics.ReconcileCountMetrics,
timeMetrics *metrics.ReconcileTimeMetrics, appClient kcclient.Interface, fetchFactory fetch.Factory,
func NewCRDApp(appModel *kcv1alpha1.App, log logr.Logger, appMetrics *metrics.Metrics, appClient kcclient.Interface, fetchFactory fetch.Factory,
templateFactory template.Factory, deployFactory deploy.Factory,
compInfo ComponentInfo, opts Opts) *CRDApp {

crdApp := &CRDApp{appModel: appModel, log: log, countMetrics: appMetrics, appClient: appClient}
crdApp := &CRDApp{appModel: appModel, log: log, countMetrics: appMetrics.ReconcileCountMetrics, appClient: appClient}

crdApp.app = NewApp(*appModel, Hooks{
BlockDeletion: crdApp.blockDeletion,
UnblockDeletion: crdApp.unblockDeletion,
UpdateStatus: crdApp.updateStatus,
WatchChanges: crdApp.watchChanges,
}, fetchFactory, templateFactory, deployFactory, log, opts, appMetrics, timeMetrics, compInfo)
}, fetchFactory, templateFactory, deployFactory, log, opts, appMetrics, compInfo)

return crdApp
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0

package metrics

// Metrics holds all metrics
type Metrics struct {
*ReconcileCountMetrics
*ReconcileTimeMetrics
}
16 changes: 7 additions & 9 deletions pkg/packageinstall/packageinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ type PackageInstallCR struct {
compInfo ComponentInfo
opts Opts

countMetrics *metrics.ReconcileCountMetrics
timeMetrics *metrics.ReconcileTimeMetrics
pkgMetrics *metrics.Metrics

firstReconcile bool
}
Expand All @@ -70,11 +69,10 @@ type Opts struct {

func NewPackageInstallCR(model *pkgingv1alpha1.PackageInstall, log logr.Logger,
kcclient kcclient.Interface, pkgclient pkgclient.Interface, coreClient kubernetes.Interface,
compInfo ComponentInfo, opts Opts, countMetrics *metrics.ReconcileCountMetrics, timeMetrics *metrics.ReconcileTimeMetrics) *PackageInstallCR {
compInfo ComponentInfo, opts Opts, pkgMetrics *metrics.Metrics) *PackageInstallCR {

return &PackageInstallCR{model: model, unmodifiedModel: model.DeepCopy(), log: log,
kcclient: kcclient, pkgclient: pkgclient, coreClient: coreClient, compInfo: compInfo, opts: opts, countMetrics: countMetrics,
timeMetrics: timeMetrics}
kcclient: kcclient, pkgclient: pkgclient, coreClient: coreClient, compInfo: compInfo, opts: opts, pkgMetrics: pkgMetrics}
}

func (pi *PackageInstallCR) Reconcile() (reconcile.Result, error) {
Expand All @@ -83,7 +81,7 @@ func (pi *PackageInstallCR) Reconcile() (reconcile.Result, error) {
func(st kcv1alpha1.GenericStatus) { pi.model.Status.GenericStatus = st },
}

pi.countMetrics.InitMetrics(packageInstallType, pi.model.Name, pi.model.Namespace)
pi.pkgMetrics.ReconcileCountMetrics.InitMetrics(packageInstallType, pi.model.Name, pi.model.Namespace)

var result reconcile.Result
var err error
Expand Down Expand Up @@ -111,12 +109,12 @@ func (pi *PackageInstallCR) Reconcile() (reconcile.Result, error) {

func (pi *PackageInstallCR) reconcile(modelStatus *reconciler.Status) (reconcile.Result, error) {
pi.log.Info("Reconciling")
pi.countMetrics.RegisterReconcileAttempt(packageInstallType, pi.model.Name, pi.model.Namespace)
pi.pkgMetrics.ReconcileCountMetrics.RegisterReconcileAttempt(packageInstallType, pi.model.Name, pi.model.Namespace)

reconcileStartTime := time.Now()
pi.firstReconcile = pi.countMetrics.GetReconcileAttemptCounterValue("pkgi", pi.model.Name, pi.model.Namespace) == 1
pi.firstReconcile = pi.pkgMetrics.ReconcileCountMetrics.GetReconcileAttemptCounterValue("pkgi", pi.model.Name, pi.model.Namespace) == 1
defer func() {
pi.timeMetrics.RegisterOverallTime(packageInstallType, pi.model.Name, pi.model.Namespace,
pi.pkgMetrics.ReconcileTimeMetrics.RegisterOverallTime(packageInstallType, pi.model.Name, pi.model.Namespace,
pi.firstReconcile, time.Since(reconcileStartTime))
}()

Expand Down
Loading

0 comments on commit 0174469

Please sign in to comment.