Remove error return from Scope interface. (#2857)

This was inherited from the statsd interface but never used. This allows us to
remove one of our errcheck exceptions.
This commit is contained in:
Jacob Hoffman-Andrews 2017-07-11 10:54:06 -07:00 committed by Roland Bracewell Shoemaker
parent 957a68c72b
commit 9c7482fa94
6 changed files with 52 additions and 76 deletions

View File

@ -709,7 +709,7 @@ func TestExtensions(t *testing.T) {
// With ca.enableMustStaple = false, should issue successfully and not add // With ca.enableMustStaple = false, should issue successfully and not add
// Must Staple. // Must Staple.
stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1))
noStapleCert := sign(mustStapleCSR) noStapleCert := sign(mustStapleCSR)
test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1) test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1)
test.AssertEquals(t, countMustStaple(t, noStapleCert), 0) test.AssertEquals(t, countMustStaple(t, noStapleCert), 0)
@ -717,20 +717,20 @@ func TestExtensions(t *testing.T) {
// With ca.enableMustStaple = true, a TLS feature extension should put a must-staple // With ca.enableMustStaple = true, a TLS feature extension should put a must-staple
// extension into the cert // extension into the cert
ca.enableMustStaple = true ca.enableMustStaple = true
stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1))
singleStapleCert := sign(mustStapleCSR) singleStapleCert := sign(mustStapleCSR)
test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1) test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1)
test.AssertEquals(t, countMustStaple(t, singleStapleCert), 1) test.AssertEquals(t, countMustStaple(t, singleStapleCert), 1)
// Even if there are multiple TLS Feature extensions, only one extension should be included // Even if there are multiple TLS Feature extensions, only one extension should be included
stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1))
duplicateMustStapleCert := sign(duplicateMustStapleCSR) duplicateMustStapleCert := sign(duplicateMustStapleCSR)
test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1) test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1)
test.AssertEquals(t, countMustStaple(t, duplicateMustStapleCert), 1) test.AssertEquals(t, countMustStaple(t, duplicateMustStapleCert), 1)
// ... but if it doesn't ask for stapling, there should be an error // ... but if it doesn't ask for stapling, there should be an error
stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionTLSFeature, int64(1))
stats.EXPECT().Inc(metricCSRExtensionTLSFeatureInvalid, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionTLSFeatureInvalid, int64(1))
ca.signatureCount.Reset() ca.signatureCount.Reset()
_, err = ca.IssueCertificate(ctx, *tlsFeatureUnknownCSR, 1001) _, err = ca.IssueCertificate(ctx, *tlsFeatureUnknownCSR, 1001)
test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 0) test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 0)
@ -739,7 +739,7 @@ func TestExtensions(t *testing.T) {
// Unsupported extensions should be silently ignored, having the same // Unsupported extensions should be silently ignored, having the same
// extensions as the TLS Feature cert above, minus the TLS Feature Extension // extensions as the TLS Feature cert above, minus the TLS Feature Extension
stats.EXPECT().Inc(metricCSRExtensionOther, int64(1)).Return(nil) stats.EXPECT().Inc(metricCSRExtensionOther, int64(1))
unsupportedExtensionCert := sign(unsupportedExtensionCSR) unsupportedExtensionCert := sign(unsupportedExtensionCSR)
test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1) test.AssertEquals(t, signatureCountByPurpose("cert", ca.signatureCount), 1)
test.AssertEquals(t, len(unsupportedExtensionCert.Extensions), len(singleStapleCert.Extensions)-1) test.AssertEquals(t, len(unsupportedExtensionCert.Extensions), len(singleStapleCert.Extensions)-1)

View File

@ -31,30 +31,24 @@ func (_m *MockScope) EXPECT() *_MockScopeRecorder {
return _m.recorder return _m.recorder
} }
func (_m *MockScope) Gauge(_param0 string, _param1 int64) error { func (_m *MockScope) Gauge(_param0 string, _param1 int64) {
ret := _m.ctrl.Call(_m, "Gauge", _param0, _param1) _m.ctrl.Call(_m, "Gauge", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) Gauge(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) Gauge(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Gauge", arg0, arg1) return _mr.mock.ctrl.RecordCall(_mr.mock, "Gauge", arg0, arg1)
} }
func (_m *MockScope) GaugeDelta(_param0 string, _param1 int64) error { func (_m *MockScope) GaugeDelta(_param0 string, _param1 int64) {
ret := _m.ctrl.Call(_m, "GaugeDelta", _param0, _param1) _m.ctrl.Call(_m, "GaugeDelta", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) GaugeDelta(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) GaugeDelta(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "GaugeDelta", arg0, arg1) return _mr.mock.ctrl.RecordCall(_mr.mock, "GaugeDelta", arg0, arg1)
} }
func (_m *MockScope) Inc(_param0 string, _param1 int64) error { func (_m *MockScope) Inc(_param0 string, _param1 int64) {
ret := _m.ctrl.Call(_m, "Inc", _param0, _param1) _m.ctrl.Call(_m, "Inc", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) Inc(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) Inc(arg0, arg1 interface{}) *gomock.Call {
@ -87,30 +81,24 @@ func (_mr *_MockScopeRecorder) NewScope(arg0 ...interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "NewScope", arg0...) return _mr.mock.ctrl.RecordCall(_mr.mock, "NewScope", arg0...)
} }
func (_m *MockScope) SetInt(_param0 string, _param1 int64) error { func (_m *MockScope) SetInt(_param0 string, _param1 int64) {
ret := _m.ctrl.Call(_m, "SetInt", _param0, _param1) _m.ctrl.Call(_m, "SetInt", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) SetInt(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) SetInt(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "SetInt", arg0, arg1) return _mr.mock.ctrl.RecordCall(_mr.mock, "SetInt", arg0, arg1)
} }
func (_m *MockScope) Timing(_param0 string, _param1 int64) error { func (_m *MockScope) Timing(_param0 string, _param1 int64) {
ret := _m.ctrl.Call(_m, "Timing", _param0, _param1) _m.ctrl.Call(_m, "Timing", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) Timing(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) Timing(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Timing", arg0, arg1) return _mr.mock.ctrl.RecordCall(_mr.mock, "Timing", arg0, arg1)
} }
func (_m *MockScope) TimingDuration(_param0 string, _param1 time.Duration) error { func (_m *MockScope) TimingDuration(_param0 string, _param1 time.Duration) {
ret := _m.ctrl.Call(_m, "TimingDuration", _param0, _param1) _m.ctrl.Call(_m, "TimingDuration", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
} }
func (_mr *_MockScopeRecorder) TimingDuration(arg0, arg1 interface{}) *gomock.Call { func (_mr *_MockScopeRecorder) TimingDuration(arg0, arg1 interface{}) *gomock.Call {

View File

@ -12,12 +12,12 @@ import (
type Scope interface { type Scope interface {
NewScope(scopes ...string) Scope NewScope(scopes ...string) Scope
Inc(stat string, value int64) error Inc(stat string, value int64)
Gauge(stat string, value int64) error Gauge(stat string, value int64)
GaugeDelta(stat string, value int64) error GaugeDelta(stat string, value int64)
Timing(stat string, delta int64) error Timing(stat string, delta int64)
TimingDuration(stat string, delta time.Duration) error TimingDuration(stat string, delta time.Duration)
SetInt(stat string, value int64) error SetInt(stat string, value int64)
MustRegister(...prometheus.Collector) MustRegister(...prometheus.Collector)
} }
@ -55,40 +55,34 @@ func (s *promScope) NewScope(scopes ...string) Scope {
} }
// Inc increments the given stat and adds the Scope's prefix to the name // Inc increments the given stat and adds the Scope's prefix to the name
func (s *promScope) Inc(stat string, value int64) error { func (s *promScope) Inc(stat string, value int64) {
s.autoCounter(s.statName(stat)).Add(float64(value)) s.autoCounter(s.statName(stat)).Add(float64(value))
return nil
} }
// Gauge sends a gauge stat and adds the Scope's prefix to the name // Gauge sends a gauge stat and adds the Scope's prefix to the name
func (s *promScope) Gauge(stat string, value int64) error { func (s *promScope) Gauge(stat string, value int64) {
s.autoGauge(s.statName(stat)).Set(float64(value)) s.autoGauge(s.statName(stat)).Set(float64(value))
return nil
} }
// GaugeDelta sends the change in a gauge stat and adds the Scope's prefix to the name // GaugeDelta sends the change in a gauge stat and adds the Scope's prefix to the name
func (s *promScope) GaugeDelta(stat string, value int64) error { func (s *promScope) GaugeDelta(stat string, value int64) {
s.autoGauge(s.statName(stat)).Add(float64(value)) s.autoGauge(s.statName(stat)).Add(float64(value))
return nil
} }
// Timing sends a latency stat and adds the Scope's prefix to the name // Timing sends a latency stat and adds the Scope's prefix to the name
func (s *promScope) Timing(stat string, delta int64) error { func (s *promScope) Timing(stat string, delta int64) {
s.autoSummary(s.statName(stat) + "_seconds").Observe(float64(delta)) s.autoSummary(s.statName(stat) + "_seconds").Observe(float64(delta))
return nil
} }
// TimingDuration sends a latency stat as a time.Duration and adds the Scope's // TimingDuration sends a latency stat as a time.Duration and adds the Scope's
// prefix to the name // prefix to the name
func (s *promScope) TimingDuration(stat string, delta time.Duration) error { func (s *promScope) TimingDuration(stat string, delta time.Duration) {
s.autoSummary(s.statName(stat) + "_seconds").Observe(delta.Seconds()) s.autoSummary(s.statName(stat) + "_seconds").Observe(delta.Seconds())
return nil
} }
// SetInt sets a stat's integer value and adds the Scope's prefix to the name // SetInt sets a stat's integer value and adds the Scope's prefix to the name
func (s *promScope) SetInt(stat string, value int64) error { func (s *promScope) SetInt(stat string, value int64) {
s.autoGauge(s.statName(stat)).Set(float64(value)) s.autoGauge(s.statName(stat)).Set(float64(value))
return nil
} }
// statName construct a name for a stat based on the prefix of this scope, plus // statName construct a name for a stat based on the prefix of this scope, plus
@ -111,28 +105,22 @@ func (n noopScope) NewScope(scopes ...string) Scope {
return n return n
} }
func (n noopScope) Inc(stat string, value int64) error { func (n noopScope) Inc(stat string, value int64) {
return nil
} }
func (n noopScope) Gauge(stat string, value int64) error { func (n noopScope) Gauge(stat string, value int64) {
return nil
} }
func (n noopScope) GaugeDelta(stat string, value int64) error { func (n noopScope) GaugeDelta(stat string, value int64) {
return nil
} }
func (n noopScope) Timing(stat string, delta int64) error { func (n noopScope) Timing(stat string, delta int64) {
return nil
} }
func (n noopScope) TimingDuration(stat string, delta time.Duration) error { func (n noopScope) TimingDuration(stat string, delta time.Duration) {
return nil
} }
func (n noopScope) SetInt(stat string, value int64) error { func (n noopScope) SetInt(stat string, value int64) {
return nil
} }
func (n noopScope) MustRegister(...prometheus.Collector) { func (n noopScope) MustRegister(...prometheus.Collector) {

View File

@ -308,8 +308,8 @@ func TestBasicSuccessful(t *testing.T) {
statName := pub.ctLogs[0].statName statName := pub.ctLogs[0].statName
log.Clear() log.Clear()
scope.EXPECT().NewScope(statName).Return(scope) scope.EXPECT().NewScope(statName).Return(scope)
scope.EXPECT().Inc("Submits", int64(1)).Return(nil) scope.EXPECT().Inc("Submits", int64(1))
scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any()).Return(nil) scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any())
err = pub.SubmitToCT(ctx, leaf.Raw) err = pub.SubmitToCT(ctx, leaf.Raw)
test.AssertNotError(t, err, "Certificate submission failed") test.AssertNotError(t, err, "Certificate submission failed")
test.AssertEquals(t, len(log.GetAllMatching("Failed to.*")), 0) test.AssertEquals(t, len(log.GetAllMatching("Failed to.*")), 0)
@ -318,8 +318,8 @@ func TestBasicSuccessful(t *testing.T) {
pub.issuerBundle = []ct.ASN1Cert{} pub.issuerBundle = []ct.ASN1Cert{}
log.Clear() log.Clear()
scope.EXPECT().NewScope(statName).Return(scope) scope.EXPECT().NewScope(statName).Return(scope)
scope.EXPECT().Inc("Submits", int64(1)).Return(nil) scope.EXPECT().Inc("Submits", int64(1))
scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any()).Return(nil) scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any())
err = pub.SubmitToCT(ctx, leaf.Raw) err = pub.SubmitToCT(ctx, leaf.Raw)
test.AssertNotError(t, err, "Certificate submission failed") test.AssertNotError(t, err, "Certificate submission failed")
test.AssertEquals(t, len(log.GetAllMatching("Failed to.*")), 0) test.AssertEquals(t, len(log.GetAllMatching("Failed to.*")), 0)
@ -358,9 +358,9 @@ func TestUnexpectedError(t *testing.T) {
log.Clear() log.Clear()
scope.EXPECT().NewScope(statName).Return(scope) scope.EXPECT().NewScope(statName).Return(scope)
scope.EXPECT().Inc("Submits", int64(1)).Return(nil) scope.EXPECT().Inc("Submits", int64(1))
scope.EXPECT().Inc("Errors", int64(1)).Return(nil) scope.EXPECT().Inc("Errors", int64(1))
scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any()).Return(nil) scope.EXPECT().TimingDuration("SubmitLatency", gomock.Any())
err = pub.SubmitToCT(ctx, leaf.Raw) err = pub.SubmitToCT(ctx, leaf.Raw)
test.AssertNotError(t, err, "Certificate submission failed") test.AssertNotError(t, err, "Certificate submission failed")
test.AssertEquals(t, len(log.GetAllMatching("Failed .*http://localhost:"+strconv.Itoa(port))), 1) test.AssertEquals(t, len(log.GetAllMatching("Failed .*http://localhost:"+strconv.Itoa(port))), 1)

View File

@ -212,7 +212,7 @@ fi
if [[ "$RUN" =~ "errcheck" ]] ; then if [[ "$RUN" =~ "errcheck" ]] ; then
start_context "errcheck" start_context "errcheck"
run_and_expect_silence errcheck \ run_and_expect_silence errcheck \
-ignore io:Write,os:Remove,net/http:Write,github.com/letsencrypt/boulder/metrics:.* \ -ignore io:Write,os:Remove,net/http:Write \
$(echo ${TESTPATHS} | tr ' ' '\n' | grep -v test) $(echo ${TESTPATHS} | tr ' ' '\n' | grep -v test)
end_context #errcheck end_context #errcheck
fi fi

View File

@ -866,8 +866,8 @@ func TestPerformValidationInvalid(t *testing.T) {
defer ctrl.Finish() defer ctrl.Finish()
mockScope := mock_metrics.NewMockScope(ctrl) mockScope := mock_metrics.NewMockScope(ctrl)
va.stats = mockScope va.stats = mockScope
mockScope.EXPECT().TimingDuration("Validations.dns-01.invalid", gomock.Any()).Return(nil) mockScope.EXPECT().TimingDuration("Validations.dns-01.invalid", gomock.Any())
mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).AnyTimes()
chalDNS := createChallenge(core.ChallengeTypeDNS01) chalDNS := createChallenge(core.ChallengeTypeDNS01)
_, prob := va.PerformValidation(context.Background(), "foo.com", chalDNS, core.Authorization{}) _, prob := va.PerformValidation(context.Background(), "foo.com", chalDNS, core.Authorization{})
@ -881,8 +881,8 @@ func TestDNSValidationEmpty(t *testing.T) {
defer ctrl.Finish() defer ctrl.Finish()
mockScope := mock_metrics.NewMockScope(ctrl) mockScope := mock_metrics.NewMockScope(ctrl)
va.stats = mockScope va.stats = mockScope
mockScope.EXPECT().TimingDuration("Validations.dns-01.invalid", gomock.Any()).Return(nil) mockScope.EXPECT().TimingDuration("Validations.dns-01.invalid", gomock.Any())
mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).AnyTimes()
chalDNS := createChallenge(core.ChallengeTypeDNS01) chalDNS := createChallenge(core.ChallengeTypeDNS01)
_, prob := va.PerformValidation( _, prob := va.PerformValidation(
@ -900,8 +900,8 @@ func TestPerformValidationValid(t *testing.T) {
defer ctrl.Finish() defer ctrl.Finish()
mockScope := mock_metrics.NewMockScope(ctrl) mockScope := mock_metrics.NewMockScope(ctrl)
va.stats = mockScope va.stats = mockScope
mockScope.EXPECT().TimingDuration("Validations.dns-01.valid", gomock.Any()).Return(nil) mockScope.EXPECT().TimingDuration("Validations.dns-01.valid", gomock.Any())
mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() mockScope.EXPECT().Inc(gomock.Any(), gomock.Any()).AnyTimes()
// create a challenge with well known token // create a challenge with well known token
chalDNS := core.DNSChallenge01() chalDNS := core.DNSChallenge01()
@ -1271,7 +1271,7 @@ func TestFallbackDialer(t *testing.T) {
va.stats = scope va.stats = scope
// We expect the IPV4 Fallback stat to be incremented // We expect the IPV4 Fallback stat to be incremented
scope.EXPECT().Inc("IPv4Fallback", int64(1)).Return(nil) scope.EXPECT().Inc("IPv4Fallback", int64(1))
// The validation is expected to succeed with IPv6First enabled even though // The validation is expected to succeed with IPv6First enabled even though
// the V6 server doesn't exist because we fallback to the IPv4 address. // the V6 server doesn't exist because we fallback to the IPv4 address.
@ -1324,7 +1324,7 @@ func TestFallbackTLS(t *testing.T) {
va.stats = scope va.stats = scope
// We expect the IPV4 Fallback stat to be incremented // We expect the IPV4 Fallback stat to be incremented
scope.EXPECT().Inc("IPv4Fallback", int64(1)).Return(nil) scope.EXPECT().Inc("IPv4Fallback", int64(1))
// The validation is expected to succeed now that IPv6First is enabled by the // The validation is expected to succeed now that IPv6First is enabled by the
// fallback to the IPv4 address that has a test server waiting // fallback to the IPv4 address that has a test server waiting