Skip to content

Commit

Permalink
Rename providers to metricproviders
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Oct 9, 2019
1 parent 6ef23fc commit 29975f0
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test:

.PHONY: mocks
mocks:
mockery -dir ./providers -name Provider -output ./providers/mocks
mockery -dir ./metricproviders -name Provider -output ./providers/mocks

.PHONY: manifests
manifests:
Expand Down
3 changes: 2 additions & 1 deletion analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (c *AnalysisController) runMeasurements(run *v1alpha1.AnalysisRun, tasks []
}

if newMeasurement.Status.Completed() {
log.Infof("measurement completed %s", newMeasurement.Status)
if newMeasurement.FinishedAt == nil {
finishedAt := metav1.Now()
newMeasurement.FinishedAt = &finishedAt
Expand All @@ -213,7 +214,7 @@ func (c *AnalysisController) runMeasurements(run *v1alpha1.AnalysisRun, tasks []
metricResult.Count++
case v1alpha1.AnalysisStatusError:
metricResult.Error++
log.Warnf("metric errored: %s", newMeasurement.Message)
log.Warnf("measurement had error: %s", newMeasurement.Message)
}
}
if t.incompleteMeasurement == nil {
Expand Down
50 changes: 48 additions & 2 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func TestReconcileAnalysisRunTerminateSiblingAfterFail(t *testing.T) {
defer f.Close()
c, _, _ := f.newController(noResyncPeriodFunc)

// mocks terminate to cancel the inProgress measurement
// mocks terminate to cancel the in-progress measurement
f.provider.On("Terminate", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(newMeasurement(v1alpha1.AnalysisStatusSuccessful), nil)

for _, status := range []v1alpha1.AnalysisStatus{v1alpha1.AnalysisStatusFailed, v1alpha1.AnalysisStatusInconclusive, v1alpha1.AnalysisStatusError} {
Expand All @@ -811,10 +811,56 @@ func TestReconcileAnalysisRunTerminateSiblingAfterFail(t *testing.T) {
assert.Equal(t, status, newRun.Status.Status)
assert.Equal(t, status, newRun.Status.MetricResults[1].Status)
assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, newRun.Status.MetricResults[0].Status)
// ensure the inProgress measurement is now terminated
// ensure the in-progress measurement is now terminated
assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, newRun.Status.MetricResults[0].Measurements[0].Status)
assert.NotNil(t, newRun.Status.MetricResults[0].Measurements[0].FinishedAt)
assert.Equal(t, "metric terminated", newRun.Status.MetricResults[0].Message)
assert.Equal(t, "metric terminated", newRun.Status.MetricResults[0].Measurements[0].Message)
}
}

func TestReconcileAnalysisRunResumeInProgress(t *testing.T) {
f := newFixture(t)
defer f.Close()
c, _, _ := f.newController(noResyncPeriodFunc)

run := v1alpha1.AnalysisRun{
Spec: v1alpha1.AnalysisRunSpec{
AnalysisSpec: v1alpha1.AnalysisTemplateSpec{
Metrics: []v1alpha1.Metric{
{
Name: "test",
Provider: v1alpha1.MetricProvider{
Job: &v1alpha1.JobMetric{},
},
},
},
},
},
Status: &v1alpha1.AnalysisRunStatus{
Status: v1alpha1.AnalysisStatusRunning,
MetricResults: []v1alpha1.MetricResult{
{
Name: "test",
Status: v1alpha1.AnalysisStatusRunning,
Measurements: []v1alpha1.Measurement{
{
Status: v1alpha1.AnalysisStatusRunning,
StartedAt: timePtr(metav1.NewTime(time.Now().Add(-60 * time.Second))),
},
},
},
},
},
}

// mocks resume to complete the in-progress measurement
f.provider.On("Resume", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(newMeasurement(v1alpha1.AnalysisStatusSuccessful), nil)

newRun := c.reconcileAnalysisRun(&run)

assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, newRun.Status.Status)
assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, newRun.Status.MetricResults[0].Status)
assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, newRun.Status.MetricResults[0].Measurements[0].Status)
assert.NotNil(t, newRun.Status.MetricResults[0].Measurements[0].FinishedAt)
}
6 changes: 3 additions & 3 deletions analysis/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/argoproj/argo-rollouts/controller/metrics"
"github.com/argoproj/argo-rollouts/metricproviders"
register "github.com/argoproj/argo-rollouts/pkg/apis/rollouts"
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
clientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned"
informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions/rollouts/v1alpha1"
listers "github.com/argoproj/argo-rollouts/pkg/client/listers/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/providers"
controllerutil "github.com/argoproj/argo-rollouts/utils/controller"
logutil "github.com/argoproj/argo-rollouts/utils/log"
)
Expand All @@ -39,7 +39,7 @@ type AnalysisController struct {

metricsServer *metrics.MetricsServer

newProvider func(logCtx log.Entry, metric v1alpha1.Metric) (providers.Provider, error)
newProvider func(logCtx log.Entry, metric v1alpha1.Metric) (metricproviders.Provider, error)

// used for unit testing
enqueueAnalysis func(obj interface{})
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewAnalysisController(
controllerutil.EnqueueAfter(obj, duration, analysisRunWorkQueue)
}

providerFactory := providers.ProviderFactory{
providerFactory := metricproviders.ProviderFactory{
KubeClient: controller.kubeclientset,
JobLister: jobInformer.Lister(),
}
Expand Down
6 changes: 3 additions & 3 deletions analysis/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/argoproj/argo-rollouts/controller/metrics"
"github.com/argoproj/argo-rollouts/metricproviders"
"github.com/argoproj/argo-rollouts/metricproviders/mocks"
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned/fake"
informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions"
"github.com/argoproj/argo-rollouts/providers"
"github.com/argoproj/argo-rollouts/providers/mocks"
)

var (
Expand Down Expand Up @@ -116,7 +116,7 @@ func (f *fixture) newController(resync resyncFunc) (*AnalysisController, informe
c.enqueueAnalysis(obj)
}
f.provider = &mocks.Provider{}
c.newProvider = func(logCtx log.Entry, metric v1alpha1.Metric) (providers.Provider, error) {
c.newProvider = func(logCtx log.Entry, metric v1alpha1.Metric) (metricproviders.Provider, error) {
return f.provider, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"k8s.io/klog"

"github.com/argoproj/argo-rollouts/controller"
jobprovider "github.com/argoproj/argo-rollouts/metricproviders/job"
clientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned"
informers "github.com/argoproj/argo-rollouts/pkg/client/informers/externalversions"
"github.com/argoproj/argo-rollouts/pkg/signals"
jobprovider "github.com/argoproj/argo-rollouts/providers/job"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions providers/provider.go → metricproviders/metricproviders.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package providers
package metricproviders

import (
"fmt"
Expand All @@ -7,9 +7,9 @@ import (
"k8s.io/client-go/kubernetes"
batchlisters "k8s.io/client-go/listers/batch/v1"

"github.com/argoproj/argo-rollouts/metricproviders/job"
"github.com/argoproj/argo-rollouts/metricproviders/prometheus"
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/providers/job"
"github.com/argoproj/argo-rollouts/providers/prometheus"
)

// Provider methods to query a external systems and generate a measurement
Expand Down
68 changes: 68 additions & 0 deletions metricproviders/mocks/Provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions providers/mocks/Provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29975f0

Please sign in to comment.