Showing 20 of 44 total issues
Function caduceus
has 150 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func caduceus(arguments []string) int {
beginCaduceus := time.Now()
var (
f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
Function authenticationMiddleware
has 148 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
Function Metrics
has 120 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: IncomingQueueDepth,
Help: "The depth of the queue behind the incoming handlers.",
Method CaduceusOutboundSender.send
has 87 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (obs *CaduceusOutboundSender) send(urls *ring.Ring, secret, acceptType string, msg *wrp.Message) {
defer func() {
if r := recover(); nil != r {
obs.droppedPanic.Add(1.0)
obs.logger.Error("goroutine send() panicked", zap.String("id", obs.id), zap.Any("panic", r))
File outboundSender.go
has 519 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
Method CaduceusOutboundSender.Update
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
// Validate the failure URL, if present
if "" != wh.Webhook.FailureURL {
if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
Function authenticationMiddleware
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ServerHandler.ServeHTTP
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
eventType := unknownEventType
// find time difference, add to metric after function finishes
defer func(s time.Time) {
sh.recordQueueLatencyToHistogram(s, eventType)
Function getDoErrReason
has 13 return statements (exceeds 4 allowed). Open
Open
func getDoErrReason(err error) string {
var d *net.DNSError
if err == nil {
return noErrReason
} else if errors.Is(err, context.DeadlineExceeded) {
Method CaduceusOutboundSender.Queue
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (obs *CaduceusOutboundSender) Queue(msg *wrp.Message) {
obs.mutex.RLock()
deliverUntil := obs.deliverUntil
dropUntil := obs.dropUntil
events := obs.events
Method OutboundSenderFactory.New
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
return
}
Function caduceus
has 11 return statements (exceeds 4 allowed). Open
Open
func caduceus(arguments []string) int {
beginCaduceus := time.Now()
var (
f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
Function authenticationMiddleware
has 10 return statements (exceeds 4 allowed). Open
Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
Function NewPrimaryHandler
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewPrimaryHandler(l *zap.Logger, v *viper.Viper, registry xmetrics.Registry, sw *ServerHandler, webhookSvc ancla.Service, router *mux.Router, prevVersionSupport bool) (*mux.Router, error) {
Avoid deeply nested control flow statements. Open
Open
} else if errors.Is(err, &net.ParseError{}) {
return parseAddrErrReason
} else if errors.Is(err, net.InvalidAddrError("")) {
return invalidAddrReason
} else if errors.As(err, &d) {
Method OutboundSenderFactory.New
has 6 return statements (exceeds 4 allowed). Open
Open
func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
return
}
Method CaduceusOutboundSender.queueOverflow
has 6 return statements (exceeds 4 allowed). Open
Open
func (obs *CaduceusOutboundSender) queueOverflow() {
obs.mutex.Lock()
if time.Now().Before(obs.dropUntil) {
obs.mutex.Unlock()
return
Method ServerHandler.ServeHTTP
has 6 return statements (exceeds 4 allowed). Open
Open
func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
eventType := unknownEventType
// find time difference, add to metric after function finishes
defer func(s time.Time) {
sh.recordQueueLatencyToHistogram(s, eventType)
Method CaduceusOutboundSender.Update
has 6 return statements (exceeds 4 allowed). Open
Open
func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
// Validate the failure URL, if present
if "" != wh.Webhook.FailureURL {
if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
Method CaduceusOutboundSender.Update
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
// Validate the failure URL, if present
if "" != wh.Webhook.FailureURL {
if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"