Skip to content

Commit cc0f45e

Browse files
authored
unit tests for monitoring schedule (#123)
Description of changes: - sdk.go coverage 70.3% - Custom code hooks 100% - Overall custom code > 95% By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f67ea1d commit cc0f45e

22 files changed

+1183
-65
lines changed

pkg/resource/monitoring_schedule/manager_test_suite_test.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
"errors"
1818
"fmt"
1919

20+
"path/filepath"
21+
"testing"
22+
23+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
24+
2025
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2126
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2227
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
@@ -27,9 +32,7 @@ import (
2732
"github.com/google/go-cmp/cmp"
2833
"github.com/google/go-cmp/cmp/cmpopts"
2934
"go.uber.org/zap/zapcore"
30-
"path/filepath"
3135
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
32-
"testing"
3336
)
3437

3538
// provideResourceManagerWithMockSDKAPI accepts MockSageMakerAPI and returns pointer to resourceManager
@@ -103,15 +106,29 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
103106
ac := a.(*resource)
104107
bc := b.(*resource)
105108
// Ignore LastTransitionTime since it gets updated each run.
106-
opts := []cmp.Option{cmpopts.EquateEmpty(), cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime")}
109+
opts := []cmp.Option{cmpopts.EquateEmpty(), cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime"),
110+
cmpopts.IgnoreFields(svcapitypes.MonitoringScheduleStatus{}, "CreationTime"),
111+
cmpopts.IgnoreFields(svcapitypes.MonitoringScheduleStatus{}, "LastModifiedTime")}
107112

113+
var specMatch = false
114+
if cmp.Equal(ac.ko.Spec, bc.ko.Spec, opts...) {
115+
specMatch = true
116+
} else {
117+
fmt.Printf("Difference ko.Spec (-expected +actual):\n\n")
118+
fmt.Println(cmp.Diff(ac.ko.Spec, bc.ko.Spec, opts...))
119+
specMatch = false
120+
}
121+
122+
var statusMatch = false
108123
if cmp.Equal(ac.ko.Status, bc.ko.Status, opts...) {
109-
return true
124+
statusMatch = true
110125
} else {
111-
fmt.Printf("Difference (-expected +actual):\n\n")
126+
fmt.Printf("Difference ko.Status (-expected +actual):\n\n")
112127
fmt.Println(cmp.Diff(ac.ko.Status, bc.ko.Status, opts...))
113-
return false
128+
statusMatch = false
114129
}
130+
131+
return statusMatch && specMatch
115132
}
116133

117134
// Checks to see if the given yaml file, with name stored as expectation,

pkg/resource/monitoring_schedule/testdata/monitoring_schedule/v1alpha1/ms_invalid_before_create.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

pkg/resource/monitoring_schedule/testdata/monitoring_schedule/v1alpha1/ms_invalid_create_attempted.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"MonitoringScheduleArn": "arn:aws:sagemaker:us-west-2:123456789012:monitoring-schedule/unit-testing-monitoring-schedule"
3+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"CreationTime": "2021-10-17T06:17:40.4Z",
3+
"EndpointName": "xgboost-churn",
4+
"FailureReason": null,
5+
"LastModifiedTime": "2021-10-17T06:21:47.452Z",
6+
"LastMonitoringExecutionSummary": null,
7+
"MonitoringScheduleArn": "arn:aws:sagemaker:us-west-2:123456789012:monitoring-schedule/unit-testing-monitoring-schedule",
8+
"MonitoringScheduleConfig": {
9+
"MonitoringJobDefinition": {
10+
"BaselineConfig": {
11+
"BaseliningJobName": null,
12+
"ConstraintsResource": {
13+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/baselining/constraints.json"
14+
},
15+
"StatisticsResource": {
16+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/baselining/statistics.json"
17+
}
18+
},
19+
"Environment": null,
20+
"MonitoringAppSpecification": {
21+
"ContainerArguments": null,
22+
"ContainerEntrypoint": null,
23+
"ImageUri": "159807026194.dkr.ecr.us-west-2.amazonaws.com/sagemaker-model-monitor-analyzer",
24+
"PostAnalyticsProcessorSourceUri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/code/postprocessor.py",
25+
"RecordPreprocessorSourceUri": null
26+
},
27+
"MonitoringInputs": [
28+
{
29+
"EndpointInput": {
30+
"EndTimeOffset": null,
31+
"EndpointName": "xgboost-churn",
32+
"FeaturesAttribute": null,
33+
"InferenceAttribute": null,
34+
"LocalPath": "/opt/ml/processing/input/endpoint",
35+
"ProbabilityAttribute": null,
36+
"ProbabilityThresholdAttribute": null,
37+
"S3DataDistributionType": "FullyReplicated",
38+
"S3InputMode": "File",
39+
"StartTimeOffset": null
40+
}
41+
}
42+
],
43+
"MonitoringOutputConfig": {
44+
"KmsKeyId": null,
45+
"MonitoringOutputs": [
46+
{
47+
"S3Output": {
48+
"LocalPath": "/opt/ml/processing/output",
49+
"S3UploadMode": "Continuous",
50+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/reports"
51+
}
52+
}
53+
]
54+
},
55+
"MonitoringResources": {
56+
"ClusterConfig": {
57+
"InstanceCount": 1,
58+
"InstanceType": "ml.m5.large",
59+
"VolumeKmsKeyId": null,
60+
"VolumeSizeInGB": 20
61+
}
62+
},
63+
"NetworkConfig": null,
64+
"RoleArn": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role",
65+
"StoppingCondition": {
66+
"MaxRuntimeInSeconds": 1800
67+
}
68+
},
69+
"MonitoringJobDefinitionName": null,
70+
"MonitoringType": "DataQuality",
71+
"ScheduleConfig": {
72+
"ScheduleExpression": "cron(0 * ? * * *)"
73+
}
74+
},
75+
"MonitoringScheduleName": "unit-testing-monitoring-schedule",
76+
"MonitoringScheduleStatus": "Scheduled",
77+
"MonitoringType": "DataQuality"
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"CreationTime": "2021-10-17T06:17:40.4Z",
3+
"EndpointName": "xgboost-churn",
4+
"FailureReason": null,
5+
"LastModifiedTime": "2021-10-17T06:21:47.452Z",
6+
"LastMonitoringExecutionSummary": null,
7+
"MonitoringScheduleArn": "arn:aws:sagemaker:us-west-2:123456789012:monitoring-schedule/unit-testing-monitoring-schedule",
8+
"MonitoringScheduleConfig": {
9+
"MonitoringJobDefinition": {
10+
"BaselineConfig": {
11+
"BaseliningJobName": null,
12+
"ConstraintsResource": {
13+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/baselining/constraints.json"
14+
},
15+
"StatisticsResource": {
16+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/baselining/statistics.json"
17+
}
18+
},
19+
"Environment": null,
20+
"MonitoringAppSpecification": {
21+
"ContainerArguments": null,
22+
"ContainerEntrypoint": null,
23+
"ImageUri": "159807026194.dkr.ecr.us-west-2.amazonaws.com/sagemaker-model-monitor-analyzer",
24+
"PostAnalyticsProcessorSourceUri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/code/postprocessor.py",
25+
"RecordPreprocessorSourceUri": null
26+
},
27+
"MonitoringInputs": [
28+
{
29+
"EndpointInput": {
30+
"EndTimeOffset": null,
31+
"EndpointName": "xgboost-churn",
32+
"FeaturesAttribute": null,
33+
"InferenceAttribute": null,
34+
"LocalPath": "/opt/ml/processing/input/endpoint",
35+
"ProbabilityAttribute": null,
36+
"ProbabilityThresholdAttribute": null,
37+
"S3DataDistributionType": "FullyReplicated",
38+
"S3InputMode": "File",
39+
"StartTimeOffset": null
40+
}
41+
}
42+
],
43+
"MonitoringOutputConfig": {
44+
"KmsKeyId": null,
45+
"MonitoringOutputs": [
46+
{
47+
"S3Output": {
48+
"LocalPath": "/opt/ml/processing/output",
49+
"S3UploadMode": "Continuous",
50+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/data_quality_job_definition/reports"
51+
}
52+
}
53+
]
54+
},
55+
"MonitoringResources": {
56+
"ClusterConfig": {
57+
"InstanceCount": 1,
58+
"InstanceType": "ml.m5.large",
59+
"VolumeKmsKeyId": null,
60+
"VolumeSizeInGB": 20
61+
}
62+
},
63+
"NetworkConfig": null,
64+
"RoleArn": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role",
65+
"StoppingCondition": {
66+
"MaxRuntimeInSeconds": 1900
67+
}
68+
},
69+
"MonitoringJobDefinitionName": null,
70+
"MonitoringType": "DataQuality",
71+
"ScheduleConfig": {
72+
"ScheduleExpression": "cron(0 * ? * * *)"
73+
}
74+
},
75+
"MonitoringScheduleName": "unit-testing-monitoring-schedule",
76+
"MonitoringScheduleStatus": "Pending",
77+
"MonitoringType": "DataQuality"
78+
}

0 commit comments

Comments
 (0)