rancher/opni-monitoring

View on GitHub

Showing 150 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

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                          func (c *CRDStore) ListRoleBindings(ctx context.Context) (*core.RoleBindingList, error) {
                              list := &v1beta1.RoleBindingList{}
                              err := c.client.List(ctx, list, client.InNamespace(c.namespace))
                              if err != nil {
                                  return nil, err
                          Severity: Major
                          Found in pkg/storage/crds/rbac_store.go and 1 other location - About 1 hr to fix
                          pkg/storage/crds/rbac_store.go on lines 82..95

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 184.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                          func (c *CRDStore) ListRoles(ctx context.Context) (*core.RoleList, error) {
                              list := &v1beta1.RoleList{}
                              err := c.client.List(ctx, list, client.InNamespace(c.namespace))
                              if err != nil {
                                  return nil, err
                          Severity: Major
                          Found in pkg/storage/crds/rbac_store.go and 1 other location - About 1 hr to fix
                          pkg/storage/crds/rbac_store.go on lines 97..110

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 184.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          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

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                            func (e *EtcdStore) CreateRoleBinding(ctx context.Context, roleBinding *core.RoleBinding) error {
                                ctx, ca := context.WithTimeout(ctx, e.CommandTimeout)
                                defer ca()
                                data, err := protojson.Marshal(roleBinding)
                                if err != nil {
                            Severity: Major
                            Found in pkg/storage/etcd/rbac_store.go and 1 other location - About 1 hr to fix
                            pkg/storage/etcd/rbac_store.go on lines 14..26

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 174.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Severity
                            Category
                            Status
                            Source
                            Language