Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishapi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishapi
Commits
38335b90
Commit
38335b90
authored
Aug 31, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaks in the data types to improve inlining and garbage collection.
parent
bb33548c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
33 deletions
+68
-33
data.go
pkg/log/data.go
+54
-33
log_test.go
pkg/log/log_test.go
+14
-0
No files found.
pkg/log/data.go
View file @
38335b90
...
...
@@ -47,8 +47,6 @@ nonprintable(enum VSL_tag_e tag)
*/
import
"C"
import
"fmt"
// TxType is a classifier for a log transaction, indicating if it is
// the log of a client or backend request/response, a Varnish session,
// or a raw transaction.
...
...
@@ -89,7 +87,7 @@ func (txtype TxType) String() string {
case
TxRaw
:
return
"Record"
default
:
panic
(
"invalid transaction type"
)
return
"invalid transaction type"
}
}
...
...
@@ -154,7 +152,7 @@ func (reason Reason) String() string {
case
Pipe
:
return
"pipe"
default
:
panic
(
"invalid reason"
)
return
"invalid reason"
}
}
...
...
@@ -225,54 +223,77 @@ const (
// String returns "b", "c" or "-".
func
(
rt
RecordType
)
String
()
string
{
return
string
(
rt
)
switch
rt
{
case
Client
:
return
"c"
case
Backend
:
return
"b"
case
None
:
return
"-"
default
:
return
"invalid RecordType"
}
}
func
initTags
()
[]
string
{
var
tags
[]
string
// TagData contains metadata about log tags, particularly their string
// form, since a tag appears as a number in a Record. The type of the
// Tags variable is TagData[]; for a tag t, use TagData[t] to get its
// metadata.
//
// String is the Tag name that appears in the second column of default
// varnishlog output, such as "ReqHeader" for a client request header,
// or "BerespHeader" for a backend response header.
//
// If Tags[t].Legal is false, then there is no legal tag for t. No
// such tag is generated from log reads for a live instance of
// Varnish. You may encounter such a tag when reading from a binary
// log that was generated by a version of Varnish that is different
// from the version with which the Go client is currently linked.
//
// NonPrintable is true if log payloads of the type indicated by the
// tag may contain non-printable characters. If NonPrintable is false
// (which is the case for most tags), you can assume that the log
// payload contains only printable ASCII characters.
type
TagData
struct
{
String
string
Legal
bool
NonPrintable
bool
}
func
initTags
()
[]
TagData
{
var
tags
[]
TagData
if
uint8
(
C
.
slt_max
())
>
^
uint8
(
0
)
{
panic
(
"SLT__MAX > max uint8"
)
}
max
:=
int
(
C
.
slt_max
())
for
i
:=
0
;
i
<
max
;
i
++
{
if
C
.
VSL_tags
[
i
]
==
nil
{
tags
=
append
(
tags
,
fmt
.
Sprintf
(
"%d"
,
i
))
continue
tagdata
:=
TagData
{}
if
C
.
VSL_tags
[
i
]
!=
nil
{
tagdata
.
String
=
C
.
GoString
(
C
.
VSL_tags
[
i
])
tagdata
.
Legal
=
true
tagdata
.
NonPrintable
=
C
.
nonprintable
(
uint32
(
i
))
!=
0
}
tags
=
append
(
tags
,
C
.
GoString
(
C
.
VSL_tags
[
i
])
)
tags
=
append
(
tags
,
tagdata
)
}
return
tags
}
var
tags
=
initTags
()
// Tags has the type []TagData -- for a tag t in a Record, Tags[t]
// contains its metadata.
var
Tags
=
initTags
()
// A Tag is a classifier for the contents of a Record's payload,
// corresponding to the second column of default varnishlog
// output. For a Tag t,
t.String()
may be "ReqURL" for a client
// output. For a Tag t,
Tags[t].String
may be "ReqURL" for a client
// request URL, "BerespStatus" for the HTTP status of a backend
// response, and so forth.
type
Tag
uint8
// String returns the Tag name that appears in the second column of
// default varnishlog output, such as "ReqHeader" for a client request
// header, or "BerespHeader" for a backend response header.
//
// If t.String() returns the numeric value of t as a string, then
// there is no legal tag for t. No such tag is generated from log
// reads for a live instance of Varnish. You may encounter such a tag
// when reading from a binary log that was generated by a version of
// Varnish that is different from the version with which the Go client
// is currently linked.
// String returns the string form for a tag (the value in
// Tags[tag].String). This makes it easy to get the string form with
// the %s or %v verbs for a formatter in package fmt.
func
(
tag
Tag
)
String
()
string
{
return
tags
[
tag
]
}
// Nonprintable returns true if log payloads of the type indicated by
// the tag may contain non-printable characters. If Nonprintable()
// returns false (which is the case for most tags), you can assume
// that the log payload contains only printable ASCII characters.
func
(
tag
Tag
)
Nonprintable
()
bool
{
return
C
.
nonprintable
(
uint32
(
tag
))
!=
0
return
Tags
[
tag
]
.
String
}
// Payload is the type of the message contained in a Record -- the
...
...
@@ -413,7 +434,7 @@ func (status Status) String() string {
case
More
:
return
"More log transactions are pending"
default
:
panic
(
"invalid status"
)
return
"invalid status"
}
}
...
...
pkg/log/log_test.go
View file @
38335b90
...
...
@@ -30,6 +30,20 @@ package log
import
"testing"
func
TestTags
(
t
*
testing
.
T
)
{
for
i
,
tag
:=
range
Tags
{
if
Tag
(
i
)
.
String
()
!=
tag
.
String
{
t
.
Errorf
(
"Tag %d string mismatch .String()=%v "
+
"Tags[%d].String=%v"
,
i
,
Tag
(
i
)
.
String
(),
i
,
Tags
[
i
]
.
String
)
}
if
!
tag
.
Legal
&&
tag
.
String
!=
""
{
t
.
Errorf
(
"Non-empty String for illegal Tag %d: %s"
,
i
,
tag
.
String
)
}
}
}
var
expTxTypeStr
=
map
[
TxType
]
string
{
TxUnknown
:
"Unknown"
,
Sess
:
"Session"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment