rancher/opni-monitoring

View on GitHub

Showing 95 of 150 total issues

Method Reconciler.deployment has 223 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (r *Reconciler) deployment() (resources.Resource, error) {
    labels := resources.Labels()

    dep := &appsv1.Deployment{
        ObjectMeta: metav1.ObjectMeta{
Severity: Major
Found in pkg/sdk/resources/gateway/deployment.go - About 7 hrs to fix

    Method Agent.streamRulesToGateway has a Cognitive Complexity of 45 (exceeds 20 allowed). Consider refactoring.
    Open

    func (a *Agent) streamRulesToGateway(ctx context.Context) error {
        lg := a.logger
        updateC, err := a.streamRuleGroupUpdates(ctx)
        if err != nil {
            a.logger.With(
    Severity: Minor
    Found in pkg/agent/rules.go - About 4 hrs to fix

    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

    Function BuildBootstrapCmd has 122 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func BuildBootstrapCmd() *cobra.Command {
        lg := logger.New()
    
        var namespace, kubeconfig, gatewayAddress, token string
        var pins []string
    Severity: Major
    Found in pkg/opnim/commands/bootstrap.go - About 3 hrs to fix

      Function BuildGatewayCmd has 102 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func BuildGatewayCmd() *cobra.Command {
          lg := logger.New()
          var configLocation string
      
          run := func() error {
      Severity: Major
      Found in pkg/opnim/commands/gateway.go - About 3 hrs to fix

        Method MultiTenantRuleAggregator.Handle has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
        Open

        func (a *MultiTenantRuleAggregator) Handle(c *fiber.Ctx) error {
            ids := rbac.AuthorizedClusterIDs(c)
            a.logger.With(
                "request", c.Path(),
            ).Debugf("aggregating query over %d tenants", len(ids))
        Severity: Minor
        Found in plugins/cortex/pkg/cortex/aggregation.go - About 2 hrs to fix

        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 ServerConfig.handleBootstrapAuth has 96 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (h ServerConfig) handleBootstrapAuth(c *fiber.Ctx) error {
            lg := c.Context().Logger()
            authHeader := strings.TrimSpace(c.Get("Authorization"))
            if strings.TrimSpace(authHeader) == "" {
                return c.SendStatus(fiber.StatusUnauthorized)
        Severity: Major
        Found in pkg/bootstrap/server.go - About 2 hrs to fix

          Function init has 94 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func init() {
              build.Deps(Generate)
              docker.Deps(build.Build)
              test.Deps(testbin.Testbin, build.Build)
          
          
          Severity: Major
          Found in magefile.go - About 2 hrs to fix

            Function labelSelectorMatches has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
            Open

            func labelSelectorMatches(selector *core.LabelSelector, labels map[string]string) bool {
                for key, value := range selector.MatchLabels {
                    if labels[key] != value {
                        return false
                    }
            Severity: Minor
            Found in pkg/storage/selection.go - About 2 hrs to fix

            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

            Function NewAPIServer has 91 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func NewAPIServer(
                ctx context.Context,
                cfg *v1beta1.GatewayConfigSpec,
                lg *zap.SugaredLogger,
                opts ...APIServerOption,
            Severity: Major
            Found in pkg/gateway/api.go - About 2 hrs to fix

              Method Server.WatchClusters has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
              Open

              func (m *Server) WatchClusters(
                  in *WatchClustersRequest,
                  stream Management_WatchClustersServer,
              ) error {
                  if err := validation.Validate(in); err != nil {
              Severity: Minor
              Found in pkg/management/clusters.go - About 2 hrs to fix

              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 MultiTenantRuleAggregator.Handle has 86 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (a *MultiTenantRuleAggregator) Handle(c *fiber.Ctx) error {
                  ids := rbac.AuthorizedClusterIDs(c)
                  a.logger.With(
                      "request", c.Path(),
                  ).Debugf("aggregating query over %d tenants", len(ids))
              Severity: Major
              Found in plugins/cortex/pkg/cortex/aggregation.go - About 2 hrs to fix

                Method WebUIServer.ListenAndServe has 83 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (ws *WebUIServer) ListenAndServe() error {
                    ws.mu.Lock()
                    defer ws.mu.Unlock()
                    lg := ws.logger
                    listener, err := net.Listen("tcp4", ws.config.Spec.Management.WebListenAddress)
                Severity: Major
                Found in pkg/webui/webui.go - About 2 hrs to fix

                  Method Reconciler.rbac has 80 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (r *Reconciler) rbac() ([]resources.Resource, error) {
                      serviceAccount := &corev1.ServiceAccount{
                          ObjectMeta: metav1.ObjectMeta{
                              Name:      "opni-monitoring",
                              Namespace: r.gateway.Namespace,
                  Severity: Major
                  Found in pkg/sdk/resources/gateway/rbac.go - About 2 hrs to fix

                    Function BuildAgentCmd has 75 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func BuildAgentCmd() *cobra.Command {
                        lg := logger.New()
                        var configLocation string
                    
                        agentCmd := &cobra.Command{
                    Severity: Minor
                    Found in pkg/opnim/commands/agent.go - About 2 hrs to fix

                      Method Reconciler.configMap has 74 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (r *Reconciler) configMap() (resources.Resource, error) {
                          gatewayConf := &cfgv1beta1.GatewayConfig{
                              TypeMeta: cfgmeta.TypeMeta{
                                  Kind:       "GatewayConfig",
                                  APIVersion: "v1beta1",
                      Severity: Minor
                      Found in pkg/sdk/resources/gateway/configmap.go - About 1 hr to fix

                        Method Server.configureApiExtensionDirector has 73 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func (m *Server) configureApiExtensionDirector(ctx context.Context) StreamDirector {
                            lg := m.logger
                            lg.Infof("loading api extensions from %d plugins", len(m.apiExtPlugins))
                            methodTable := map[string]*UnknownStreamMetadata{}
                            for _, plugin := range m.apiExtPlugins {
                        Severity: Minor
                        Found in pkg/management/extensions.go - About 1 hr to fix

                          Function New has 69 lines of code (exceeds 50 allowed). Consider refactoring.
                          Open

                          func New(ctx context.Context, conf *v1beta1.AgentConfig, opts ...AgentOption) (*Agent, error) {
                              lg := logger.New().Named("agent")
                              options := AgentOptions{}
                              options.Apply(opts...)
                          
                          
                          Severity: Minor
                          Found in pkg/agent/agent.go - About 1 hr to fix

                            Method ClientConfig.Bootstrap has 68 lines of code (exceeds 50 allowed). Consider refactoring.
                            Open

                            func (c *ClientConfig) Bootstrap(
                                ctx context.Context,
                                ident ident.Provider,
                            ) (keyring.Keyring, error) {
                                if c.Token == nil {
                            Severity: Minor
                            Found in pkg/bootstrap/client.go - About 1 hr to fix

                              Function DecodeAuthHeader has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
                              Open

                              func DecodeAuthHeader(header string) (id []byte, nonce uuid.UUID, mac []byte, err error) {
                                  if !strings.HasPrefix(header, "MAC ") {
                                      return nil, uuid.Nil, nil, errors.New("incorrect authorization type")
                                  }
                                  trimmed := strings.TrimSpace(strings.TrimPrefix(header, "MAC"))
                              Severity: Minor
                              Found in pkg/b2mac/header.go - About 1 hr to fix

                              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 Reconciler.optionalContainerPorts has 64 lines of code (exceeds 50 allowed). Consider refactoring.
                              Open

                              func (r *Reconciler) optionalContainerPorts() ([]corev1.ContainerPort, error) {
                                  lg := r.logger
                                  var ports []corev1.ContainerPort
                                  if addr := r.gateway.Spec.Management.GRPCListenAddress; strings.HasPrefix(addr, "tcp://") {
                                      parts := strings.Split(addr, ":")
                              Severity: Minor
                              Found in pkg/sdk/resources/gateway/ports.go - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language