Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ineffecient module detector method #10

Merged
merged 4 commits into from Dec 11, 2016

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Dec 11, 2016

Fix #9

Add cache mechanism for core detector. The following is an example of a deep check detecting that contains single module.

Before

tflint -c .tflint.hcl.config  29.35s user 1.08s system 79% cpu 38.119 total

After

tflint -c .tflint.hcl.config  13.53s user 0.47s system 77% cpu 18.154 total

package detector

import (
"github.com/aws/aws-sdk-go/service/ec2"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] could not import github.com/aws/aws-sdk-go/service/ec2 (can't find import: github.com/wata727/tflint/vendor/github.com/aws/aws-sdk-go/service/ec2)


import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] could not import github.com/aws/aws-sdk-go/service/iam (can't find import: github.com/wata727/tflint/vendor/github.com/aws/aws-sdk-go/service/iam)

import (
"reflect"

"github.com/hashicorp/hcl/hcl/ast"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] could not import github.com/hashicorp/hcl/hcl/ast (can't find import: github.com/wata727/tflint/vendor/github.com/hashicorp/hcl/hcl/ast)

"reflect"

"github.com/hashicorp/hcl/hcl/ast"
"github.com/hashicorp/hcl/hcl/parser"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] could not import github.com/hashicorp/hcl/hcl/parser (can't find import: github.com/wata727/tflint/vendor/github.com/hashicorp/hcl/hcl/parser)

)

type ResponseCache struct {
DescribeImagesOutput *ec2.DescribeImagesOutput
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: ec2


type ResponseCache struct {
DescribeImagesOutput *ec2.DescribeImagesOutput
ListInstanceProfilesOutput *iam.ListInstanceProfilesOutput
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: iam

EvalConfig *evaluator.Evaluator
Logger *logger.Logger
Error bool
ListMap map[string]*ast.ObjectList
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: ast

@@ -14,7 +22,7 @@ func (d *Detector) DetectAwsInstanceDefaultStandardVolume(issues *[]*issue.Issue
}
}

func (d *Detector) detectForBlockDevices(issues *[]*issue.Issue, item *ast.ObjectItem, filename string, device string) {
func (d *AwsInstanceDefaultStandardVolumeDetector) detectForBlockDevices(issues *[]*issue.Issue, item *ast.ObjectItem, filename string, device string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: ast

d.Logger.Error(err)
d.Error = true
if d.ResponseCache.ListInstanceProfilesOutput == nil {
resp, err := d.AwsClient.Iam.ListInstanceProfiles(&iam.ListInstanceProfilesInput{})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: iam
  • [gotype] cannot use &(iam.ListInstanceProfilesInput literal) (value of type *invalid type) as *github.com/aws/aws-sdk-go/service/iam.ListInstanceProfilesInput value in argument to d.AwsClient.Iam.ListInstanceProfiles

d.Logger.Error(err)
d.Error = true
}
d.ResponseCache.ListInstanceProfilesOutput = resp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] cannot use resp (variable of type *github.com/aws/aws-sdk-go/service/iam.ListInstanceProfilesOutput) as *invalid type value in assignment

}
for _, iamProfile := range resp.InstanceProfiles {
for _, iamProfile := range d.ResponseCache.ListInstanceProfilesOutput.InstanceProfiles {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] invalid operation: d.ResponseCache.ListInstanceProfilesOutput (variable of type *invalid type) has no field or method InstanceProfiles
  • [gotype] cannot range over d.ResponseCache.ListInstanceProfilesOutput.InstanceProfiles (invalid operand)

d.Logger.Error(err)
d.Error = true
if d.ResponseCache.DescribeImagesOutput == nil {
resp, err := d.AwsClient.Ec2.DescribeImages(&ec2.DescribeImagesInput{})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: ec2
  • [gotype] cannot use &(ec2.DescribeImagesInput literal) (value of type *invalid type) as *github.com/aws/aws-sdk-go/service/ec2.DescribeImagesInput value in argument to d.AwsClient.Ec2.DescribeImages

d.Logger.Error(err)
d.Error = true
}
d.ResponseCache.DescribeImagesOutput = resp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] cannot use resp (variable of type *github.com/aws/aws-sdk-go/service/ec2.DescribeImagesOutput) as *invalid type value in assignment

}
for _, image := range resp.Images {
for _, image := range d.ResponseCache.DescribeImagesOutput.Images {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] invalid operation: d.ResponseCache.DescribeImagesOutput (variable of type *invalid type) has no field or method Images
  • [gotype] cannot range over d.ResponseCache.DescribeImagesOutput.Images (invalid operand)

},
Logger: d.Logger,
Error: false,
moduleDetector, err := NewDetector(m.ListMap, d.Config)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] cannot use m.ListMap (variable of type map[string]*github.com/hashicorp/hcl/hcl/ast.ObjectList) as map[string]*invalid type value in argument to NewDetector

}

func TestDetectByCreatorName(creatorMethod string, src string, c *config.Config, awsClient *config.AwsClient, issues *[]*issue.Issue) {
listMap := make(map[string]*ast.ObjectList)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: ast


func TestDetectByCreatorName(creatorMethod string, src string, c *config.Config, awsClient *config.AwsClient, issues *[]*issue.Issue) {
listMap := make(map[string]*ast.ObjectList)
root, _ := parser.Parse([]byte(src))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] undeclared name: parser

list, _ := root.Node.(*ast.ObjectList)
listMap["test.tf"] = list

evalConfig, _ := evaluator.NewEvaluator(listMap, c)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [gotype] cannot use listMap (variable of type map[string]*invalid type) as map[string]*github.com/hashicorp/hcl/hcl/ast.ObjectList value in argument to evaluator.NewEvaluator

@@ -7,7 +7,15 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsDbInstanceDefaultParameterGroup(issues *[]*issue.Issue) {
type AwsDBInstanceDefaultParameterGroupDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsDBInstanceDefaultParameterGroupDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsDBInstanceDefaultParameterGroupDetector() *AwsDBInstanceDefaultParameterGroupDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsDBInstanceDefaultParameterGroupDetector should have comment or be unexported

return &AwsDBInstanceDefaultParameterGroupDetector{d}
}

func (d *AwsDBInstanceDefaultParameterGroupDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsDBInstanceDefaultParameterGroupDetector.Detect should have comment or be unexported

@@ -7,7 +7,15 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsElasticacheClusterDefaultParameterGroup(issues *[]*issue.Issue) {
type AwsElastiCacheClusterDefaultParameterGroupDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsElastiCacheClusterDefaultParameterGroupDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsElastiCacheClusterDefaultParameterGroupDetector() *AwsElastiCacheClusterDefaultParameterGroupDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsElastiCacheClusterDefaultParameterGroupDetector should have comment or be unexported

return &AwsElastiCacheClusterDefaultParameterGroupDetector{d}
}

func (d *AwsElastiCacheClusterDefaultParameterGroupDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsElastiCacheClusterDefaultParameterGroupDetector.Detect should have comment or be unexported

@@ -5,7 +5,15 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsInstanceDefaultStandardVolume(issues *[]*issue.Issue) {
type AwsInstanceDefaultStandardVolumeDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstanceDefaultStandardVolumeDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstanceDefaultStandardVolumeDetector() *AwsInstanceDefaultStandardVolumeDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstanceDefaultStandardVolumeDetector should have comment or be unexported

return &AwsInstanceDefaultStandardVolumeDetector{d}
}

func (d *AwsInstanceDefaultStandardVolumeDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceDefaultStandardVolumeDetector.Detect should have comment or be unexported

@@ -7,19 +7,30 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsInstanceInvalidAmi(issues *[]*issue.Issue) {
type AwsInstanceInvalidAMIDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstanceInvalidAMIDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstanceInvalidAMIDetector() *AwsInstanceInvalidAMIDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstanceInvalidAMIDetector should have comment or be unexported

return &AwsInstanceInvalidAMIDetector{d}
}

func (d *AwsInstanceInvalidAMIDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceInvalidAMIDetector.Detect should have comment or be unexported

@@ -7,19 +7,30 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsInstanceInvalidIamProfile(issues *[]*issue.Issue) {
type AwsInstanceInvalidIAMProfileDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstanceInvalidIAMProfileDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstanceInvalidIAMProfileDetector() *AwsInstanceInvalidIAMProfileDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstanceInvalidIAMProfileDetector should have comment or be unexported

return &AwsInstanceInvalidIAMProfileDetector{d}
}

func (d *AwsInstanceInvalidIAMProfileDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceInvalidIAMProfileDetector.Detect should have comment or be unexported

@@ -6,7 +6,15 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsInstanceInvalidType(issues *[]*issue.Issue) {
type AwsInstanceInvalidTypeDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstanceInvalidTypeDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstanceInvalidTypeDetector() *AwsInstanceInvalidTypeDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstanceInvalidTypeDetector should have comment or be unexported

return &AwsInstanceInvalidTypeDetector{d}
}

func (d *AwsInstanceInvalidTypeDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceInvalidTypeDetector.Detect should have comment or be unexported

@@ -2,7 +2,15 @@ package detector

import "github.com/wata727/tflint/issue"

func (d *Detector) DetectAwsInstanceNotSpecifiedIamProfile(issues *[]*issue.Issue) {
type AwsInstanceNotSpecifiedIAMProfileDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstanceNotSpecifiedIAMProfileDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstanceNotSpecifiedIAMProfileDetector() *AwsInstanceNotSpecifiedIAMProfileDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstanceNotSpecifiedIAMProfileDetector should have comment or be unexported

return &AwsInstanceNotSpecifiedIAMProfileDetector{d}
}

func (d *AwsInstanceNotSpecifiedIAMProfileDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceNotSpecifiedIAMProfileDetector.Detect should have comment or be unexported

@@ -17,3 +25,7 @@ func (d *Detector) DetectAwsInstanceNotSpecifiedIamProfile(issues *[]*issue.Issu
}
}
}

func (d *AwsInstanceNotSpecifiedIAMProfileDetector) Inherit(original *AwsInstanceNotSpecifiedIAMProfileDetector) *AwsInstanceNotSpecifiedIAMProfileDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstanceNotSpecifiedIAMProfileDetector.Inherit should have comment or be unexported

@@ -6,7 +6,15 @@ import (
"github.com/wata727/tflint/issue"
)

func (d *Detector) DetectAwsInstancePreviousType(issues *[]*issue.Issue) {
type AwsInstancePreviousTypeDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type AwsInstancePreviousTypeDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateAwsInstancePreviousTypeDetector() *AwsInstancePreviousTypeDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateAwsInstancePreviousTypeDetector should have comment or be unexported

return &AwsInstancePreviousTypeDetector{d}
}

func (d *AwsInstancePreviousTypeDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method AwsInstancePreviousTypeDetector.Detect should have comment or be unexported

"github.com/aws/aws-sdk-go/service/iam"
)

type ResponseCache struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type ResponseCache should have comment or be unexported

"github.com/wata727/tflint/issue"
)

type TestDetector struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported type TestDetector should have comment or be unexported

*Detector
}

func (d *Detector) CreateTestDetector() *TestDetector {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method Detector.CreateTestDetector should have comment or be unexported

return &TestDetector{d}
}

func (d *TestDetector) Detect(issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported method TestDetector.Detect should have comment or be unexported

})
}

func TestDetectByCreatorName(creatorMethod string, src string, c *config.Config, awsClient *config.AwsClient, issues *[]*issue.Issue) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gometalinter]

  • [golint] exported function TestDetectByCreatorName should have comment or be unexported

@wata727
Copy link
Member Author

wata727 commented Dec 11, 2016

Umm... It's noisy. I have to review the settings in SideCI...

@wata727 wata727 merged commit f625a84 into master Dec 11, 2016
@wata727 wata727 deleted the improve_ineffecient_module_detector_method branch December 11, 2016 16:07
bendrucker pushed a commit that referenced this pull request Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant