-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grafana dashboard in access log and user agent
- Loading branch information
Showing
6 changed files
with
92 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
package scope | ||
|
||
import ( | ||
"context" | ||
"encoding/binary" | ||
"fmt" | ||
"math/rand" | ||
"net/http" | ||
"regexp" | ||
) | ||
|
||
var requestIdRegexp *regexp.Regexp = regexp.MustCompile("^[a-zA-Z0-9_.-]+$") | ||
var passHeaders = []string{ | ||
"X-Dashboard-Id", | ||
"X-Grafana-Org-Id", | ||
"X-Panel-Id", | ||
} | ||
|
||
func HttpRequest(r *http.Request) *http.Request { | ||
requestID := r.Header.Get("X-Request-Id") | ||
if requestID == "" || !requestIdRegexp.MatchString(requestID) { | ||
var b [16]byte | ||
binary.LittleEndian.PutUint64(b[:], rand.Uint64()) | ||
binary.LittleEndian.PutUint64(b[8:], rand.Uint64()) | ||
requestID = fmt.Sprintf("%x", b) | ||
} | ||
|
||
ctx := r.Context() | ||
ctx = WithRequestID(ctx, requestID) | ||
|
||
for _, h := range passHeaders { | ||
hv := r.Header.Get(h) | ||
if hv != "" { | ||
ctx = With(ctx, h, hv) | ||
} | ||
} | ||
|
||
return r.WithContext(ctx) | ||
} | ||
|
||
func Grafana(ctx context.Context) string { | ||
o, d, p := String(ctx, "X-Grafana-Org-Id"), String(ctx, "X-Dashboard-Id"), String(ctx, "X-Panel-Id") | ||
if o != "" || d != "" || p != "" { | ||
return fmt.Sprintf("Org:%s; Dashboard:%s; Panel:%s", o, d, p) | ||
} | ||
return "" | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package version | ||
package scope | ||
|
||
var Version string |