Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
579a1df9
Commit
579a1df9
authored
Apr 24, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a "list" method to directors, to participate in CLI::backend.list
Add a new -v flag, just because we can.
parent
47feebce
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
63 deletions
+90
-63
cache_backend.c
bin/varnishd/cache/cache_backend.c
+18
-0
cache_backend.h
bin/varnishd/cache/cache_backend.h
+1
-1
cache_backend_probe.c
bin/varnishd/cache/cache_backend_probe.c
+29
-30
cache_director.c
bin/varnishd/cache/cache_director.c
+36
-30
cache_director.h
bin/varnishd/cache/cache_director.h
+4
-0
o00004.vtc
bin/varnishtest/tests/o00004.vtc
+2
-2
No files found.
bin/varnishd/cache/cache_backend.c
View file @
579a1df9
...
...
@@ -416,6 +416,23 @@ vbe_panic(const struct director *d, struct vsb *vsb)
VSB_printf
(
vsb
,
"n_conn = %u,
\n
"
,
bp
->
n_conn
);
}
/*--------------------------------------------------------------------
*/
static
void
vbe_list
(
const
struct
director
*
d
,
struct
vsb
*
vsb
,
int
vflag
,
int
pflag
)
{
struct
backend
*
bp
;
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
CAST_OBJ_NOTNULL
(
bp
,
d
->
priv
,
BACKEND_MAGIC
);
if
(
bp
->
probe
!=
NULL
)
VBP_Status
(
vsb
,
bp
,
vflag
|
pflag
);
else
VSB_printf
(
vsb
,
"%-10s"
,
d
->
health
?
"healthy"
:
"sick"
);
}
/*--------------------------------------------------------------------
* Create a new static or dynamic director::backend instance.
*/
...
...
@@ -473,6 +490,7 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
d
->
finish
=
vbe_dir_finish
;
d
->
event
=
vbe_dir_event
;
d
->
panic
=
vbe_panic
;
d
->
list
=
vbe_list
;
d
->
destroy
=
vbe_destroy
;
d
->
health
=
1
;
...
...
bin/varnishd/cache/cache_backend.h
View file @
579a1df9
...
...
@@ -81,4 +81,4 @@ void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p,
struct
tcp_pool
*
);
void
VBP_Remove
(
struct
backend
*
b
);
void
VBP_Control
(
const
struct
backend
*
b
,
int
stop
);
void
VBP_Status
(
struct
cli
*
cli
,
const
struct
backend
*
,
int
details
);
void
VBP_Status
(
struct
vsb
*
,
const
struct
backend
*
,
int
details
);
bin/varnishd/cache/cache_backend_probe.c
View file @
579a1df9
...
...
@@ -168,9 +168,9 @@ vbp_update_backend(struct vbp_target *vt)
assert
(
i
<
sizeof
bits
);
if
(
vt
->
good
>=
vt
->
threshold
)
{
if
(
vt
->
backend
->
director
->
health
)
if
(
vt
->
backend
->
director
->
health
)
{
logmsg
=
"Still healthy"
;
else
{
}
else
{
logmsg
=
"Back healthy"
;
vt
->
backend
->
director
->
health_changed
=
VTIM_real
();
...
...
@@ -181,8 +181,9 @@ vbp_update_backend(struct vbp_target *vt)
logmsg
=
"Went sick"
;
vt
->
backend
->
director
->
health_changed
=
VTIM_real
();
}
else
}
else
{
logmsg
=
"Still sick"
;
}
vt
->
backend
->
director
->
health
=
0
;
}
VSL
(
SLT_Backend_health
,
0
,
"%s %s %s %u %u %u %.6f %.6f %s"
,
...
...
@@ -458,58 +459,56 @@ vbp_thread(struct worker *wrk, void *priv)
*/
static
void
vbp_bitmap
(
struct
cli
*
cli
,
char
c
,
uint64_t
map
,
const
char
*
lbl
)
vbp_bitmap
(
struct
vsb
*
vsb
,
char
c
,
uint64_t
map
,
const
char
*
lbl
)
{
int
i
;
uint64_t
u
=
(
1ULL
<<
63
);
V
CLI_Out
(
cli
,
" "
);
V
SB_printf
(
vsb
,
" "
);
for
(
i
=
0
;
i
<
64
;
i
++
)
{
if
(
map
&
u
)
V
CLI_Out
(
cli
,
"%c"
,
c
);
V
SB_putc
(
vsb
,
c
);
else
V
CLI_Out
(
cli
,
"-"
);
V
SB_putc
(
vsb
,
'-'
);
map
<<=
1
;
}
V
CLI_Out
(
cli
,
" %s
\n
"
,
lbl
);
V
SB_printf
(
vsb
,
" %s
\n
"
,
lbl
);
}
/*lint -e{506} constant value boolean */
/*lint -e{774} constant value boolean */
static
void
vbp_health_one
(
struct
cli
*
cli
,
const
struct
vbp_target
*
vt
)
void
VBP_Status
(
struct
vsb
*
vsb
,
const
struct
backend
*
be
,
int
details
)
{
struct
vbp_target
*
vt
;
char
buf
[
12
];
CHECK_OBJ_NOTNULL
(
be
,
BACKEND_MAGIC
);
vt
=
be
->
probe
;
CHECK_OBJ_NOTNULL
(
vt
,
VBP_TARGET_MAGIC
);
if
(
!
details
)
{
bprintf
(
buf
,
"%d/%d %s"
,
vt
->
good
,
vt
->
window
,
vt
->
backend
->
director
->
health
?
"good"
:
"bad"
);
VSB_printf
(
vsb
,
"%-10s"
,
buf
);
return
;
}
V
CLI_Out
(
cli
,
"
Current states good: %2u threshold: %2u window: %2u
\n
"
,
V
SB_printf
(
vsb
,
"
\n
Current states good: %2u threshold: %2u window: %2u
\n
"
,
vt
->
good
,
vt
->
threshold
,
vt
->
window
);
V
CLI_Out
(
cli
,
V
SB_printf
(
vsb
,
" Average response time of good probes: %.6f
\n
"
,
vt
->
avg
);
V
CLI_Out
(
cli
,
V
SB_printf
(
vsb
,
" Oldest ======================"
"============================ Newest
\n
"
);
#define BITMAP(n, c, t, b) \
if ((vt->n != 0) || (b)) \
vbp_bitmap(
cli
, (c), vt->n, (t));
vbp_bitmap(
vsb
, (c), vt->n, (t));
#include "tbl/backend_poll.h"
}
void
VBP_Status
(
struct
cli
*
cli
,
const
struct
backend
*
be
,
int
details
)
{
struct
vbp_target
*
vt
;
CHECK_OBJ_NOTNULL
(
be
,
BACKEND_MAGIC
);
vt
=
be
->
probe
;
CHECK_OBJ_NOTNULL
(
vt
,
VBP_TARGET_MAGIC
);
VCLI_Out
(
cli
,
"%d/%d"
,
vt
->
good
,
vt
->
window
);
if
(
details
)
{
VCLI_Out
(
cli
,
"
\n
"
);
vbp_health_one
(
cli
,
vt
);
}
}
/*--------------------------------------------------------------------
* Build request from probe spec
*/
...
...
bin/varnishd/cache/cache_director.c
View file @
579a1df9
...
...
@@ -38,7 +38,6 @@
#include "cache_varnishd.h"
#include "cache_director.h"
#include "cache_backend.h"
#include "vcli_serve.h"
#include "vtim.h"
...
...
@@ -279,62 +278,69 @@ VDI_Healthy(const struct director *d, double *changed)
/*---------------------------------------------------------------------*/
struct
list_args
{
unsigned
magic
;
#define LIST_ARGS_MAGIC 0x7e7cefeb
int
p
;
int
v
;
};
static
int
v_matchproto_
(
vcl_be_func
)
do_list
(
struct
cli
*
cli
,
struct
director
*
d
,
void
*
priv
)
{
int
*
probes
;
char
time_str
[
VTIM_FORMAT_SIZE
];
struct
backend
*
be
;
struct
list_args
*
la
;
AN
(
priv
);
probes
=
priv
;
CAST_OBJ_NOTNULL
(
la
,
priv
,
LIST_ARGS_MAGIC
);
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
CAST_OBJ_NOTNULL
(
be
,
d
->
priv
,
BACKEND_MAGIC
);
if
(
d
->
admin_health
==
VDI_AH_DELETED
)
return
(
0
);
VCLI_Out
(
cli
,
"
\n
%-30s"
,
d
->
cli_name
);
VCLI_Out
(
cli
,
" %-10s"
,
VDI_Ahealth
(
d
));
VCLI_Out
(
cli
,
"
\n
%-30s %-7s "
,
d
->
cli_name
,
VDI_Ahealth
(
d
));
if
(
be
->
probe
==
NULL
)
VCLI_Out
(
cli
,
" %-20s"
,
"Healthy (no probe)"
);
else
{
if
(
d
->
health
)
VCLI_Out
(
cli
,
" %-20s"
,
"Healthy "
);
else
VCLI_Out
(
cli
,
" %-20s"
,
"Sick "
);
VBP_Status
(
cli
,
be
,
*
probes
);
}
if
(
d
->
list
!=
NULL
)
d
->
list
(
d
,
cli
->
sb
,
0
,
0
);
else
VCLI_Out
(
cli
,
"%-10s"
,
d
->
health
?
"healthy"
:
"sick"
);
VTIM_format
(
d
->
health_changed
,
time_str
);
VCLI_Out
(
cli
,
" %s"
,
time_str
);
if
(
la
->
p
||
la
->
v
)
d
->
list
(
d
,
cli
->
sb
,
la
->
p
,
la
->
v
);
return
(
0
);
}
static
void
v_matchproto_
(
cli_func_t
)
cli_backend_list
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
int
probes
=
0
;
const
char
*
p
;
struct
list_args
la
[
1
];
(
void
)
priv
;
ASSERT_CLI
();
if
(
av
[
2
]
!=
NULL
&&
!
strcmp
(
av
[
2
],
"-p"
))
{
INIT_OBJ
(
la
,
LIST_ARGS_MAGIC
);
while
(
av
[
2
]
!=
NULL
&&
av
[
2
][
0
]
==
'-'
)
{
for
(
p
=
av
[
2
]
+
1
;
*
p
;
p
++
)
{
switch
(
*
p
)
{
case
'p'
:
la
->
p
=
!
la
->
p
;
break
;
case
'v'
:
la
->
p
=
!
la
->
p
;
break
;
default:
VCLI_Out
(
cli
,
"Invalid flag %c"
,
*
p
);
VCLI_SetResult
(
cli
,
CLIS_PARAM
);
return
;
}
}
av
++
;
probes
=
1
;
}
else
if
(
av
[
2
]
!=
NULL
&&
av
[
2
][
0
]
==
'-'
)
{
VCLI_Out
(
cli
,
"Invalid flags %s"
,
av
[
2
]);
VCLI_SetResult
(
cli
,
CLIS_PARAM
);
return
;
}
else
if
(
av
[
3
]
!=
NULL
)
{
}
if
(
av
[
3
]
!=
NULL
)
{
VCLI_Out
(
cli
,
"Too many arguments"
);
VCLI_SetResult
(
cli
,
CLIS_PARAM
);
return
;
}
VCLI_Out
(
cli
,
"%-30s %-
10s %-20s %s"
,
"Backend name"
,
"Admin
"
,
"
Probe"
,
"Last updated
"
);
(
void
)
VCL_IterDirector
(
cli
,
av
[
2
],
do_list
,
&
probes
);
VCLI_Out
(
cli
,
"%-30s %-
7s %-10s %s
"
,
"
Backend name"
,
"Admin"
,
"Probe"
,
"Last change
"
);
(
void
)
VCL_IterDirector
(
cli
,
av
[
2
],
do_list
,
la
);
}
/*---------------------------------------------------------------------*/
...
...
bin/varnishd/cache/cache_director.h
View file @
579a1df9
...
...
@@ -60,6 +60,8 @@ typedef void vdi_destroy_f(const struct director *);
typedef
void
vdi_panic_f
(
const
struct
director
*
,
struct
vsb
*
);
typedef
void
vdi_list_f
(
const
struct
director
*
,
struct
vsb
*
,
int
,
int
);
struct
director
{
unsigned
magic
;
#define DIRECTOR_MAGIC 0x3336351d
...
...
@@ -75,6 +77,8 @@ struct director {
vdi_event_f
*
event
;
vdi_destroy_f
*
destroy
;
vdi_panic_f
*
panic
;
vdi_list_f
*
list
;
void
*
priv
;
const
void
*
priv2
;
...
...
bin/varnishtest/tests/o00004.vtc
View file @
579a1df9
...
...
@@ -49,5 +49,5 @@ varnish v2 -vcl {
server s1 -wait
delay 1
varnish v2 -cliexpect "vcl1.bp1[ ]+probe[ ]+
Healthy[ ]+1/1
" backend.list
varnish v2 -cliexpect "vcl1.bp2[ ]+probe[ ]+
Healthy[ ]+1/1
" backend.list
varnish v2 -cliexpect "vcl1.bp1[ ]+probe[ ]+
1/1[ ]+good
" backend.list
varnish v2 -cliexpect "vcl1.bp2[ ]+probe[ ]+
1/1[ ]+good
" backend.list
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