-
Notifications
You must be signed in to change notification settings - Fork 86
Code structure Refactoring #162
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
Open
Thiyagu55
wants to merge
28
commits into
google:master
Choose a base branch
from
Thiyagu55:go-sql-implementation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3b5a535
Added support for Query Row and Query Context
Thiyagu55 f9b7cad
Added support for http-router
Thiyagu55 0cc3b08
Go-SQL Implementation done
Thiyagu55 373142d
Added README.md & copyright header
Thiyagu55 d61b985
Updated net/http
Thiyagu55 f89b7b3
Update README.md
sjs994 dc6c518
Update go-sql.go
sjs994 f7eb636
Added support for otel traceparet
Thiyagu55 935870f
PR changes for otel integration
Thiyagu55 5ac9c42
Added Unittests
Thiyagu55 5ff4995
PR changes
Thiyagu55 1ef9f62
PR changes
Thiyagu55 f79cf94
Added CI unittest pipeline
Thiyagu55 3327a3b
Added CI unittest pipeline
Thiyagu55 9749f6b
Added sqlmock module
Thiyagu55 4b5cebc
Added CI unittest pipeline
Thiyagu55 c347efb
Added gofmt tests
Thiyagu55 f27540a
Added gofmt tests
Thiyagu55 50e7ffd
Rename Package
Thiyagu55 6ce058a
updated github workflow
Thiyagu55 50aff88
updated github workflow
Thiyagu55 266ff1e
renamed github workflow
Thiyagu55 ec74286
Code structure refactoring
Thiyagu55 c328bbb
Merge branch 'go-sql-implementation' of https://github.com/Thiyagu55/…
Thiyagu55 2968a73
PR changes
Thiyagu55 cdb2c15
PR changes
Thiyagu55 fd5c508
PR changes
Thiyagu55 72278f4
PR changes
Thiyagu55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # SQLCommenter Core [In development] | ||
|
|
||
| SQLcommenter is a plugin/middleware/wrapper to augment application related information/tags with SQL Statements that can be used later to correlate user code with SQL statements. | ||
|
|
||
| This package contains configuration options, framework interface and support functions for all the sqlcommenter go modules | ||
|
|
||
| ## Installation | ||
|
|
||
| This is a support package and will be installed indirectly by other go sqlcommenter packages | ||
|
|
||
| ## Usages | ||
|
|
||
| ### Configuration | ||
|
|
||
| Users are given control over what tags they want to append by using `core.CommenterOptions` struct. | ||
|
|
||
| ```go | ||
| type CommenterOptions struct { | ||
| EnableDBDriver bool | ||
| EnableTraceparent bool // OpenTelemetry trace information | ||
| EnableRoute bool // applicable for web frameworks | ||
| EnableFramework bool // applicable for web frameworks | ||
| EnableController bool // applicable for web frameworks | ||
| EnableAction bool // applicable for web frameworks | ||
| } | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/url" | ||
| "reflect" | ||
| "runtime" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| "go.opentelemetry.io/otel/propagation" | ||
| ) | ||
|
|
||
| const ( | ||
| Route string = "route" | ||
| Controller string = "controller" | ||
| Action string = "action" | ||
| Framework string = "framework" | ||
| Driver string = "driver" | ||
| Traceparent string = "traceparent" | ||
| ) | ||
|
|
||
| type CommenterOptions struct { | ||
| EnableDBDriver bool | ||
| EnableRoute bool | ||
| EnableFramework bool | ||
| EnableController bool | ||
| EnableAction bool | ||
| EnableTraceparent bool | ||
| } | ||
|
|
||
| func encodeURL(k string) string { | ||
| return url.QueryEscape(string(k)) | ||
| } | ||
|
|
||
| func GetFunctionName(i interface{}) string { | ||
| return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() | ||
| } | ||
|
|
||
| func ConvertMapToComment(tags map[string]string) string { | ||
| var sb strings.Builder | ||
| i, sz := 0, len(tags) | ||
|
|
||
| //sort by keys | ||
| sortedKeys := make([]string, 0, len(tags)) | ||
| for k := range tags { | ||
| sortedKeys = append(sortedKeys, k) | ||
| } | ||
| sort.Strings(sortedKeys) | ||
|
|
||
| for _, key := range sortedKeys { | ||
| if i == sz-1 { | ||
| sb.WriteString(fmt.Sprintf("%s=%v", encodeURL(key), encodeURL(tags[key]))) | ||
| } else { | ||
| sb.WriteString(fmt.Sprintf("%s=%v,", encodeURL(key), encodeURL(tags[key]))) | ||
| } | ||
| i++ | ||
| } | ||
| return sb.String() | ||
| } | ||
|
|
||
| func ExtractTraceparent(ctx context.Context) propagation.MapCarrier { | ||
| // Serialize the context into carrier | ||
| propgator := propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}) | ||
| carrier := propagation.MapCarrier{} | ||
| propgator.Inject(ctx, carrier) | ||
| return carrier | ||
| } | ||
|
|
||
| type HttpRequestTagger interface { | ||
Thiyagu55 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Route() string | ||
| Action() string | ||
| Framework() string | ||
| GetContext() context.Context | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module google.com/sqlcommenter/core | ||
|
|
||
| go 1.19 | ||
|
|
||
| require go.opentelemetry.io/otel v1.10.0 | ||
|
|
||
| require go.opentelemetry.io/otel/trace v1.10.0 // indirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
| github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= | ||
| github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= | ||
| github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= | ||
| go.opentelemetry.io/otel v1.10.0 h1:Y7DTJMR6zs1xkS/upamJYk0SxxN4C9AqRd77jmZnyY4= | ||
| go.opentelemetry.io/otel v1.10.0/go.mod h1:NbvWjCthWHKBEUMpf0/v8ZRZlni86PpGFEMA9pnQSnQ= | ||
| go.opentelemetry.io/otel/trace v1.10.0 h1:npQMbR8o7mum8uF95yFbOEJffhs1sbCOfDh8zAJiH5E= | ||
| go.opentelemetry.io/otel/trace v1.10.0/go.mod h1:Sij3YYczqAdz+EhmGhE6TpTxUO5/F/AzrK+kxfGqySM= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
Thiyagu55 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "configurations": [ | ||
| { | ||
| "name": "Launch Package", | ||
| "type": "go", | ||
| "request": "launch", | ||
| "mode": "auto", | ||
| "program": "/Users/thiyagunataraj/Documents/Sqlcommenter-new/sqlcommenter/go/" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.