Skip to content

Commit 0174469

Browse files
committed
having single struct for both metrics
Signed-off-by: sethiyash <[email protected]>
1 parent c871303 commit 0174469

19 files changed

+132
-111
lines changed

cmd/controller/run.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,14 @@ func Run(opts Options, runLog logr.Logger) error {
197197
}
198198
{ // add controller for apps
199199
appFactory := app.CRDAppFactory{
200-
CoreClient: coreClient,
201-
AppClient: kcClient,
202-
KcConfig: kcConfig,
203-
CountMetrics: countMetrics,
204-
ReconcileTimeMetrics: reconcileTimeMetrics,
205-
CmdRunner: sidecarCmdExec,
206-
Kubeconf: kubeconf,
207-
CompInfo: compInfo,
208-
CacheFolder: cacheFolderApps,
200+
CoreClient: coreClient,
201+
AppClient: kcClient,
202+
KcConfig: kcConfig,
203+
AppMetrics: &metrics.Metrics{ReconcileCountMetrics: countMetrics, ReconcileTimeMetrics: reconcileTimeMetrics},
204+
CmdRunner: sidecarCmdExec,
205+
Kubeconf: kubeconf,
206+
CompInfo: compInfo,
207+
CacheFolder: cacheFolderApps,
209208
}
210209
reconciler := app.NewReconciler(kcClient, runLog.WithName("app"),
211210
appFactory, refTracker, updateStatusTracker, compInfo)
@@ -232,7 +231,8 @@ func Run(opts Options, runLog logr.Logger) error {
232231
kcClient, opts.PackagingGlobalNS, runLog.WithName("handler"))
233232

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

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

257257
{ // add controller for pkgrepositories
258258
appFactory := pkgrepository.AppFactory{
259-
CoreClient: coreClient,
260-
AppClient: kcClient,
261-
KcConfig: kcConfig,
262-
CountMetrics: countMetrics,
263-
TimeMetrics: reconcileTimeMetrics,
264-
CmdRunner: sidecarCmdExec,
265-
Kubeconf: kubeconf,
266-
CacheFolder: cacheFolderPkgRepoApps,
259+
CoreClient: coreClient,
260+
AppClient: kcClient,
261+
KcConfig: kcConfig,
262+
AppMetrics: &metrics.Metrics{ReconcileCountMetrics: countMetrics, ReconcileTimeMetrics: reconcileTimeMetrics},
263+
CmdRunner: sidecarCmdExec,
264+
Kubeconf: kubeconf,
265+
CacheFolder: cacheFolderPkgRepoApps,
267266
}
268267

269268
reconciler := pkgrepository.NewReconciler(kcClient, coreClient,

pkg/app/app.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ type App struct {
5555
memoizedKubernetesVersion string
5656
memoizedKubernetesAPIs []string
5757

58-
log logr.Logger
59-
opts Opts
60-
countMetrics *metrics.ReconcileCountMetrics
61-
timeMetrics *metrics.ReconcileTimeMetrics
58+
log logr.Logger
59+
opts Opts
60+
appMetrics *metrics.Metrics
6261

6362
isFirstReconcile bool
6463
pendingStatusUpdate bool
@@ -68,11 +67,11 @@ type App struct {
6867

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

7372
return &App{app: app, appPrev: *(app.DeepCopy()), hooks: hooks,
7473
fetchFactory: fetchFactory, templateFactory: templateFactory,
75-
deployFactory: deployFactory, log: log, opts: opts, countMetrics: appMetrics, timeMetrics: timeMetrics, compInfo: compInfo}
74+
deployFactory: deployFactory, log: log, opts: opts, appMetrics: appMetrics, compInfo: compInfo}
7675
}
7776

7877
func (a *App) Name() string { return a.app.Name }

pkg/app/app_factory.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ import (
2323

2424
// CRDAppFactory allows to create CRDApps.
2525
type CRDAppFactory struct {
26-
CoreClient kubernetes.Interface
27-
AppClient kcclient.Interface
28-
KcConfig *config.Config
29-
CountMetrics *metrics.ReconcileCountMetrics
30-
ReconcileTimeMetrics *metrics.ReconcileTimeMetrics
31-
VendirConfigHook func(vendirconf.Config) vendirconf.Config
32-
KbldAllowBuild bool
33-
CmdRunner exec.CmdRunner
34-
Kubeconf *kubeconfig.Kubeconfig
35-
CompInfo ComponentInfo
36-
DeployFactory deploy.Factory
37-
CacheFolder *memdir.TmpDir
26+
CoreClient kubernetes.Interface
27+
AppClient kcclient.Interface
28+
KcConfig *config.Config
29+
AppMetrics *metrics.Metrics
30+
VendirConfigHook func(vendirconf.Config) vendirconf.Config
31+
KbldAllowBuild bool
32+
CmdRunner exec.CmdRunner
33+
Kubeconf *kubeconfig.Kubeconfig
34+
CompInfo ComponentInfo
35+
DeployFactory deploy.Factory
36+
CacheFolder *memdir.TmpDir
3837
}
3938

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

52-
return NewCRDApp(app, log, f.CountMetrics, f.ReconcileTimeMetrics, f.AppClient, fetchFactory, templateFactory, deployFactory, f.CompInfo, Opts{
51+
return NewCRDApp(app, log, f.AppMetrics, f.AppClient, fetchFactory, templateFactory, deployFactory, f.CompInfo, Opts{
5352
DefaultSyncPeriod: f.KcConfig.AppDefaultSyncPeriod(),
5453
MinimumSyncPeriod: f.KcConfig.AppMinimumSyncPeriod(),
5554
})

pkg/app/app_reconcile.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (a *App) Reconcile(force bool) (reconcile.Result, error) {
2323

2424
var err error
2525

26-
a.countMetrics.InitMetrics(appResourceType, a.Name(), a.Namespace())
26+
a.appMetrics.ReconcileCountMetrics.InitMetrics(appResourceType, a.Name(), a.Namespace())
2727

2828
timerOpts := ReconcileTimerOpts{
2929
DefaultSyncPeriod: a.opts.DefaultSyncPeriod,
@@ -106,9 +106,9 @@ func (a *App) reconcileDeploy() error {
106106

107107
func (a *App) reconcileFetchTemplateDeploy() exec.CmdRunResult {
108108
reconcileStartTime := time.Now()
109-
a.isFirstReconcile = a.countMetrics.GetReconcileAttemptCounterValue("app", a.app.Name, a.app.Namespace) == 1
109+
a.isFirstReconcile = a.appMetrics.ReconcileCountMetrics.GetReconcileAttemptCounterValue("app", a.app.Name, a.app.Namespace) == 1
110110
defer func() {
111-
a.timeMetrics.RegisterOverallTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
111+
a.appMetrics.ReconcileTimeMetrics.RegisterOverallTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
112112
time.Since(reconcileStartTime))
113113
}()
114114

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

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

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

165-
a.timeMetrics.RegisterTemplateTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
165+
a.appMetrics.ReconcileTimeMetrics.RegisterTemplateTime(appResourceType, a.app.Name, a.app.Namespace, a.isFirstReconcile,
166166
a.app.Status.Template.UpdatedAt.Sub(templateStartTime))
167167

168168
err = a.updateStatus("marking template completed")
@@ -213,7 +213,7 @@ func (a *App) updateLastDeploy(result exec.CmdRunResult) exec.CmdRunResult {
213213
},
214214
}
215215

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

219219
return result
@@ -267,7 +267,7 @@ func (a *App) setReconciling() {
267267
Status: corev1.ConditionTrue,
268268
})
269269

270-
a.countMetrics.RegisterReconcileAttempt(appResourceType, a.app.Name, a.app.Namespace)
270+
a.appMetrics.ReconcileCountMetrics.RegisterReconcileAttempt(appResourceType, a.app.Name, a.app.Namespace)
271271
a.app.Status.FriendlyDescription = "Reconciling"
272272
}
273273

@@ -283,7 +283,7 @@ func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
283283
a.app.Status.ConsecutiveReconcileFailures++
284284
a.app.Status.ConsecutiveReconcileSuccesses = 0
285285
a.app.Status.FriendlyDescription = fmt.Sprintf("Reconcile failed: %s", result.ErrorStr())
286-
a.countMetrics.RegisterReconcileFailure(appResourceType, a.app.Name, a.app.Namespace)
286+
a.appMetrics.ReconcileCountMetrics.RegisterReconcileFailure(appResourceType, a.app.Name, a.app.Namespace)
287287
a.setUsefulErrorMessage(result)
288288
} else {
289289
a.app.Status.Conditions = append(a.app.Status.Conditions, v1alpha1.Condition{
@@ -294,7 +294,7 @@ func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
294294
a.app.Status.ConsecutiveReconcileSuccesses++
295295
a.app.Status.ConsecutiveReconcileFailures = 0
296296
a.app.Status.FriendlyDescription = "Reconcile succeeded"
297-
a.countMetrics.RegisterReconcileSuccess(appResourceType, a.app.Name, a.app.Namespace)
297+
a.appMetrics.ReconcileCountMetrics.RegisterReconcileSuccess(appResourceType, a.app.Name, a.app.Namespace)
298298
a.app.Status.UsefulErrorMessage = ""
299299
}
300300
}
@@ -307,7 +307,7 @@ func (a *App) setDeleting() {
307307
Status: corev1.ConditionTrue,
308308
})
309309

310-
a.countMetrics.RegisterReconcileDeleteAttempt(appResourceType, a.app.Name, a.app.Namespace)
310+
a.appMetrics.ReconcileCountMetrics.RegisterReconcileDeleteAttempt(appResourceType, a.app.Name, a.app.Namespace)
311311
a.app.Status.FriendlyDescription = "Deleting"
312312
}
313313

@@ -323,10 +323,10 @@ func (a *App) setDeleteCompleted(result exec.CmdRunResult) {
323323
a.app.Status.ConsecutiveReconcileFailures++
324324
a.app.Status.ConsecutiveReconcileSuccesses = 0
325325
a.app.Status.FriendlyDescription = fmt.Sprintf("Delete failed: %s", result.ErrorStr())
326-
a.countMetrics.RegisterReconcileDeleteFailed(appResourceType, a.app.Name, a.app.Namespace)
326+
a.appMetrics.ReconcileCountMetrics.RegisterReconcileDeleteFailed(appResourceType, a.app.Name, a.app.Namespace)
327327
a.setUsefulErrorMessage(result)
328328
} else {
329-
a.countMetrics.DeleteMetrics(appResourceType, a.app.Name, a.app.Namespace)
329+
a.appMetrics.ReconcileCountMetrics.DeleteMetrics(appResourceType, a.app.Name, a.app.Namespace)
330330
}
331331
}
332332

pkg/app/app_reconcile_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Test_NoInspectReconcile_IfNoDeployAttempted(t *testing.T) {
5555
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
5656
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)
5757

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

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

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

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

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

pkg/app/app_template_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Test_BuildAdditionalDownwardAPIValues_MemoizedCallCount(t *testing.T) {
6161
K8sAPIsCount: &k8sAPIsCallCount,
6262
KCVersionCount: &kcVersionCallCount,
6363
}
64-
app := NewApp(appEmpty, Hooks{}, fetchFac, tmpFac, deployFac, log, Opts{}, metrics.NewCountMetrics(), metrics.NewReconcileTimeMetrics(), fakeInfo)
64+
app := NewApp(appEmpty, Hooks{}, fetchFac, tmpFac, deployFac, log, Opts{}, &metrics.Metrics{}, fakeInfo)
6565

6666
dir, err := os.MkdirTemp("", "temp")
6767
assert.NoError(t, err)

pkg/app/app_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/exec"
1616
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/fetch"
1717
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/kubeconfig"
18+
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/metrics"
1819
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/reftracker"
1920
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/template"
2021
v1 "k8s.io/api/core/v1"
@@ -64,7 +65,7 @@ func Test_SecretRefs_RetrievesAllSecretRefs(t *testing.T) {
6465
tmpFac := template.NewFactory(k8scs, fetchFac, false, exec.NewPlainCmdRunner())
6566
deployFac := deploy.NewFactory(k8scs, kubeconfig.NewKubeconfig(k8scs, log), nil, exec.NewPlainCmdRunner(), log)
6667

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

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

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

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

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

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

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

155156
out := app.ConfigMapRefs()
156157
assert.Lenf(t, out, 0, "Expected: %s\nGot: %s\n", "No ConfigMapRefs to be returned", out)

pkg/app/crd_app.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ type CRDApp struct {
2929
}
3030

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

37-
crdApp := &CRDApp{appModel: appModel, log: log, countMetrics: appMetrics, appClient: appClient}
36+
crdApp := &CRDApp{appModel: appModel, log: log, countMetrics: appMetrics.ReconcileCountMetrics, appClient: appClient}
3837

3938
crdApp.app = NewApp(*appModel, Hooks{
4039
BlockDeletion: crdApp.blockDeletion,
4140
UnblockDeletion: crdApp.unblockDeletion,
4241
UpdateStatus: crdApp.updateStatus,
4342
WatchChanges: crdApp.watchChanges,
44-
}, fetchFactory, templateFactory, deployFactory, log, opts, appMetrics, timeMetrics, compInfo)
43+
}, fetchFactory, templateFactory, deployFactory, log, opts, appMetrics, compInfo)
4544

4645
return crdApp
4746
}

pkg/metrics/metrics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2021 VMware, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package metrics
5+
6+
// Metrics holds all metrics
7+
type Metrics struct {
8+
*ReconcileCountMetrics
9+
*ReconcileTimeMetrics
10+
}

pkg/packageinstall/packageinstall.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ type PackageInstallCR struct {
5757
compInfo ComponentInfo
5858
opts Opts
5959

60-
countMetrics *metrics.ReconcileCountMetrics
61-
timeMetrics *metrics.ReconcileTimeMetrics
60+
pkgMetrics *metrics.Metrics
6261

6362
firstReconcile bool
6463
}
@@ -70,11 +69,10 @@ type Opts struct {
7069

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

7574
return &PackageInstallCR{model: model, unmodifiedModel: model.DeepCopy(), log: log,
76-
kcclient: kcclient, pkgclient: pkgclient, coreClient: coreClient, compInfo: compInfo, opts: opts, countMetrics: countMetrics,
77-
timeMetrics: timeMetrics}
75+
kcclient: kcclient, pkgclient: pkgclient, coreClient: coreClient, compInfo: compInfo, opts: opts, pkgMetrics: pkgMetrics}
7876
}
7977

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

86-
pi.countMetrics.InitMetrics(packageInstallType, pi.model.Name, pi.model.Namespace)
84+
pi.pkgMetrics.ReconcileCountMetrics.InitMetrics(packageInstallType, pi.model.Name, pi.model.Namespace)
8785

8886
var result reconcile.Result
8987
var err error
@@ -111,12 +109,12 @@ func (pi *PackageInstallCR) Reconcile() (reconcile.Result, error) {
111109

112110
func (pi *PackageInstallCR) reconcile(modelStatus *reconciler.Status) (reconcile.Result, error) {
113111
pi.log.Info("Reconciling")
114-
pi.countMetrics.RegisterReconcileAttempt(packageInstallType, pi.model.Name, pi.model.Namespace)
112+
pi.pkgMetrics.ReconcileCountMetrics.RegisterReconcileAttempt(packageInstallType, pi.model.Name, pi.model.Namespace)
115113

116114
reconcileStartTime := time.Now()
117-
pi.firstReconcile = pi.countMetrics.GetReconcileAttemptCounterValue("pkgi", pi.model.Name, pi.model.Namespace) == 1
115+
pi.firstReconcile = pi.pkgMetrics.ReconcileCountMetrics.GetReconcileAttemptCounterValue("pkgi", pi.model.Name, pi.model.Namespace) == 1
118116
defer func() {
119-
pi.timeMetrics.RegisterOverallTime(packageInstallType, pi.model.Name, pi.model.Namespace,
117+
pi.pkgMetrics.ReconcileTimeMetrics.RegisterOverallTime(packageInstallType, pi.model.Name, pi.model.Namespace,
120118
pi.firstReconcile, time.Since(reconcileStartTime))
121119
}()
122120

0 commit comments

Comments
 (0)