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

Fix enhance param error when there are multiple params #162

Merged
merged 2 commits into from
Jan 21, 2024

Conversation

CodePrometheus
Copy link
Contributor

@CodePrometheus CodePrometheus commented Jan 21, 2024

summary

When I intercepted the following method, I found that the parameter passed to skywalking is an array, and only the first parameter can be obtained.
For example, can only get ctx, A, C and msg.

func (ch *Ch) Test(ctx context.Context, A, B string, C, D bool, msg Publishing) (*Dc, error) {}
// tools/go-agent/tools/enhancement.go:63
func EnhanceParameterNames(fields *dst.FieldList, fieldType FieldListType) []*ParameterInfo {
	if fields == nil {
		return nil
	}
	result := make([]*ParameterInfo, 0)
	for i, f := range fields.List {
		var defineName string
		switch fieldType {
		case FieldListTypeParam:
			defineName = fmt.Sprintf("skywalking_param_%d", i)
		case FieldListTypeResult:
			defineName = fmt.Sprintf("skywalking_result_%d", i)
		case FieldListTypeRecv:
			defineName = fmt.Sprintf("skywalking_recv_%d", i)
		}
		if len(f.Names) == 0 {
			f.Names = []*dst.Ident{{Name: defineName}}
			result = append(result, newParameterInfo(defineName, f.Type))
		} else {
			for _, n := range f.Names {
				if n.Name == "_" {
					*n = *dst.NewIdent(defineName)
					break
				}
			}

			for _, n := range f.Names {
				result = append(result, newParameterInfo(n.Name, f.Type))
                                 // If there are multiple parameters in f.Names, only the first element of the array will be processed here
				break
			}
		}
	}
	return result
}

@mrproliu mrproliu self-assigned this Jan 21, 2024
@mrproliu mrproliu added the enhancement New feature or request label Jan 21, 2024
@mrproliu mrproliu added this to the 0.4.0 milestone Jan 21, 2024
go.work.sum Outdated
@@ -1759,6 +1760,7 @@ golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you need to modify the go.mod? It seems no dependency update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it was caused by my executing go mod tidy locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, please restore to the upstream version.

@@ -88,7 +88,6 @@ func EnhanceParameterNames(fields *dst.FieldList, fieldType FieldListType) []*Pa

for _, n := range f.Names {
result = append(result, newParameterInfo(n.Name, f.Type))
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you help to add more test case on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done~

Copy link
Contributor

@mrproliu mrproliu left a comment

Choose a reason for hiding this comment

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

Please update this PR by comments, thanks.

Copy link
Contributor

@mrproliu mrproliu left a comment

Choose a reason for hiding this comment

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

Once the CI success, it's LGTM. Thanks.

@CodePrometheus
Copy link
Contributor Author

Thank you for your time as well, Teacher Liu.

@wu-sheng wu-sheng merged commit 322daeb into apache:main Jan 21, 2024
34 checks passed
@CodePrometheus CodePrometheus deleted the fix_param branch January 21, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants