mirror of https://github.com/grpc/grpc.git
commit
18836bec50
115 changed files with 2359 additions and 1348 deletions
@ -0,0 +1,153 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2017, Google Inc. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* * Redistributions in binary form must reproduce the above |
||||||
|
* copyright notice, this list of conditions and the following disclaimer |
||||||
|
* in the documentation and/or other materials provided with the |
||||||
|
* distribution. |
||||||
|
* * Neither the name of Google Inc. nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h" |
||||||
|
|
||||||
|
#include <grpc/support/atm.h> |
||||||
|
#include <grpc/support/log.h> |
||||||
|
|
||||||
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h" |
||||||
|
#include "src/core/lib/iomgr/error.h" |
||||||
|
#include "src/core/lib/profiling/timers.h" |
||||||
|
|
||||||
|
static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, |
||||||
|
grpc_channel_element *elem, |
||||||
|
grpc_channel_element_args *args) { |
||||||
|
return GRPC_ERROR_NONE; |
||||||
|
} |
||||||
|
|
||||||
|
static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, |
||||||
|
grpc_channel_element *elem) {} |
||||||
|
|
||||||
|
typedef struct { |
||||||
|
// Stats object to update.
|
||||||
|
grpc_grpclb_client_stats *client_stats; |
||||||
|
// State for intercepting send_initial_metadata.
|
||||||
|
grpc_closure on_complete_for_send; |
||||||
|
grpc_closure *original_on_complete_for_send; |
||||||
|
bool send_initial_metadata_succeeded; |
||||||
|
// State for intercepting recv_initial_metadata.
|
||||||
|
grpc_closure recv_initial_metadata_ready; |
||||||
|
grpc_closure *original_recv_initial_metadata_ready; |
||||||
|
bool recv_initial_metadata_succeeded; |
||||||
|
} call_data; |
||||||
|
|
||||||
|
static void on_complete_for_send(grpc_exec_ctx *exec_ctx, void *arg, |
||||||
|
grpc_error *error) { |
||||||
|
call_data *calld = arg; |
||||||
|
if (error == GRPC_ERROR_NONE) { |
||||||
|
calld->send_initial_metadata_succeeded = true; |
||||||
|
} |
||||||
|
grpc_closure_run(exec_ctx, calld->original_on_complete_for_send, |
||||||
|
GRPC_ERROR_REF(error)); |
||||||
|
} |
||||||
|
|
||||||
|
static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, void *arg, |
||||||
|
grpc_error *error) { |
||||||
|
call_data *calld = arg; |
||||||
|
if (error == GRPC_ERROR_NONE) { |
||||||
|
calld->recv_initial_metadata_succeeded = true; |
||||||
|
} |
||||||
|
grpc_closure_run(exec_ctx, calld->original_recv_initial_metadata_ready, |
||||||
|
GRPC_ERROR_REF(error)); |
||||||
|
} |
||||||
|
|
||||||
|
static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, |
||||||
|
grpc_call_element *elem, |
||||||
|
const grpc_call_element_args *args) { |
||||||
|
call_data *calld = elem->call_data; |
||||||
|
// Get stats object from context and take a ref.
|
||||||
|
GPR_ASSERT(args->context != NULL); |
||||||
|
GPR_ASSERT(args->context[GRPC_GRPCLB_CLIENT_STATS].value != NULL); |
||||||
|
calld->client_stats = grpc_grpclb_client_stats_ref( |
||||||
|
args->context[GRPC_GRPCLB_CLIENT_STATS].value); |
||||||
|
// Record call started.
|
||||||
|
grpc_grpclb_client_stats_add_call_started(calld->client_stats); |
||||||
|
return GRPC_ERROR_NONE; |
||||||
|
} |
||||||
|
|
||||||
|
static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
||||||
|
const grpc_call_final_info *final_info, |
||||||
|
grpc_closure *ignored) { |
||||||
|
call_data *calld = elem->call_data; |
||||||
|
// Record call finished, optionally setting client_failed_to_send and
|
||||||
|
// received.
|
||||||
|
grpc_grpclb_client_stats_add_call_finished( |
||||||
|
false /* drop_for_rate_limiting */, false /* drop_for_load_balancing */, |
||||||
|
!calld->send_initial_metadata_succeeded /* client_failed_to_send */, |
||||||
|
calld->recv_initial_metadata_succeeded /* known_received */, |
||||||
|
calld->client_stats); |
||||||
|
// All done, so unref the stats object.
|
||||||
|
grpc_grpclb_client_stats_unref(calld->client_stats); |
||||||
|
} |
||||||
|
|
||||||
|
static void start_transport_stream_op_batch( |
||||||
|
grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
||||||
|
grpc_transport_stream_op_batch *batch) { |
||||||
|
call_data *calld = elem->call_data; |
||||||
|
GPR_TIMER_BEGIN("clr_start_transport_stream_op_batch", 0); |
||||||
|
// Intercept send_initial_metadata.
|
||||||
|
if (batch->send_initial_metadata) { |
||||||
|
calld->original_on_complete_for_send = batch->on_complete; |
||||||
|
grpc_closure_init(&calld->on_complete_for_send, on_complete_for_send, calld, |
||||||
|
grpc_schedule_on_exec_ctx); |
||||||
|
batch->on_complete = &calld->on_complete_for_send; |
||||||
|
} |
||||||
|
// Intercept recv_initial_metadata.
|
||||||
|
if (batch->recv_initial_metadata) { |
||||||
|
calld->original_recv_initial_metadata_ready = |
||||||
|
batch->payload->recv_initial_metadata.recv_initial_metadata_ready; |
||||||
|
grpc_closure_init(&calld->recv_initial_metadata_ready, |
||||||
|
recv_initial_metadata_ready, calld, |
||||||
|
grpc_schedule_on_exec_ctx); |
||||||
|
batch->payload->recv_initial_metadata.recv_initial_metadata_ready = |
||||||
|
&calld->recv_initial_metadata_ready; |
||||||
|
} |
||||||
|
// Chain to next filter.
|
||||||
|
grpc_call_next_op(exec_ctx, elem, batch); |
||||||
|
GPR_TIMER_END("clr_start_transport_stream_op_batch", 0); |
||||||
|
} |
||||||
|
|
||||||
|
const grpc_channel_filter grpc_client_load_reporting_filter = { |
||||||
|
start_transport_stream_op_batch, |
||||||
|
grpc_channel_next_op, |
||||||
|
sizeof(call_data), |
||||||
|
init_call_elem, |
||||||
|
grpc_call_stack_ignore_set_pollset_or_pollset_set, |
||||||
|
destroy_call_elem, |
||||||
|
0, // sizeof(channel_data)
|
||||||
|
init_channel_elem, |
||||||
|
destroy_channel_elem, |
||||||
|
grpc_call_next_get_peer, |
||||||
|
grpc_channel_next_get_info, |
||||||
|
"client_load_reporting"}; |
@ -0,0 +1,133 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2017, Google Inc. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* * Redistributions in binary form must reproduce the above |
||||||
|
* copyright notice, this list of conditions and the following disclaimer |
||||||
|
* in the documentation and/or other materials provided with the |
||||||
|
* distribution. |
||||||
|
* * Neither the name of Google Inc. nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h" |
||||||
|
|
||||||
|
#include <grpc/support/alloc.h> |
||||||
|
#include <grpc/support/atm.h> |
||||||
|
#include <grpc/support/sync.h> |
||||||
|
#include <grpc/support/useful.h> |
||||||
|
|
||||||
|
#include "src/core/lib/channel/channel_args.h" |
||||||
|
|
||||||
|
#define GRPC_ARG_GRPCLB_CLIENT_STATS "grpc.grpclb_client_stats" |
||||||
|
|
||||||
|
struct grpc_grpclb_client_stats { |
||||||
|
gpr_refcount refs; |
||||||
|
gpr_atm num_calls_started; |
||||||
|
gpr_atm num_calls_finished; |
||||||
|
gpr_atm num_calls_finished_with_drop_for_rate_limiting; |
||||||
|
gpr_atm num_calls_finished_with_drop_for_load_balancing; |
||||||
|
gpr_atm num_calls_finished_with_client_failed_to_send; |
||||||
|
gpr_atm num_calls_finished_known_received; |
||||||
|
}; |
||||||
|
|
||||||
|
grpc_grpclb_client_stats* grpc_grpclb_client_stats_create() { |
||||||
|
grpc_grpclb_client_stats* client_stats = gpr_zalloc(sizeof(*client_stats)); |
||||||
|
gpr_ref_init(&client_stats->refs, 1); |
||||||
|
return client_stats; |
||||||
|
} |
||||||
|
|
||||||
|
grpc_grpclb_client_stats* grpc_grpclb_client_stats_ref( |
||||||
|
grpc_grpclb_client_stats* client_stats) { |
||||||
|
gpr_ref(&client_stats->refs); |
||||||
|
return client_stats; |
||||||
|
} |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_unref(grpc_grpclb_client_stats* client_stats) { |
||||||
|
if (gpr_unref(&client_stats->refs)) { |
||||||
|
gpr_free(client_stats); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_add_call_started( |
||||||
|
grpc_grpclb_client_stats* client_stats) { |
||||||
|
gpr_atm_full_fetch_add(&client_stats->num_calls_started, (gpr_atm)1); |
||||||
|
} |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_add_call_finished( |
||||||
|
bool finished_with_drop_for_rate_limiting, |
||||||
|
bool finished_with_drop_for_load_balancing, |
||||||
|
bool finished_with_client_failed_to_send, bool finished_known_received, |
||||||
|
grpc_grpclb_client_stats* client_stats) { |
||||||
|
gpr_atm_full_fetch_add(&client_stats->num_calls_finished, (gpr_atm)1); |
||||||
|
if (finished_with_drop_for_rate_limiting) { |
||||||
|
gpr_atm_full_fetch_add( |
||||||
|
&client_stats->num_calls_finished_with_drop_for_rate_limiting, |
||||||
|
(gpr_atm)1); |
||||||
|
} |
||||||
|
if (finished_with_drop_for_load_balancing) { |
||||||
|
gpr_atm_full_fetch_add( |
||||||
|
&client_stats->num_calls_finished_with_drop_for_load_balancing, |
||||||
|
(gpr_atm)1); |
||||||
|
} |
||||||
|
if (finished_with_client_failed_to_send) { |
||||||
|
gpr_atm_full_fetch_add( |
||||||
|
&client_stats->num_calls_finished_with_client_failed_to_send, |
||||||
|
(gpr_atm)1); |
||||||
|
} |
||||||
|
if (finished_known_received) { |
||||||
|
gpr_atm_full_fetch_add(&client_stats->num_calls_finished_known_received, |
||||||
|
(gpr_atm)1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void atomic_get_and_reset_counter(int64_t* value, gpr_atm* counter) { |
||||||
|
*value = (int64_t)gpr_atm_acq_load(counter); |
||||||
|
gpr_atm_full_fetch_add(counter, (gpr_atm)(-*value)); |
||||||
|
} |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_get( |
||||||
|
grpc_grpclb_client_stats* client_stats, int64_t* num_calls_started, |
||||||
|
int64_t* num_calls_finished, |
||||||
|
int64_t* num_calls_finished_with_drop_for_rate_limiting, |
||||||
|
int64_t* num_calls_finished_with_drop_for_load_balancing, |
||||||
|
int64_t* num_calls_finished_with_client_failed_to_send, |
||||||
|
int64_t* num_calls_finished_known_received) { |
||||||
|
atomic_get_and_reset_counter(num_calls_started, |
||||||
|
&client_stats->num_calls_started); |
||||||
|
atomic_get_and_reset_counter(num_calls_finished, |
||||||
|
&client_stats->num_calls_finished); |
||||||
|
atomic_get_and_reset_counter( |
||||||
|
num_calls_finished_with_drop_for_rate_limiting, |
||||||
|
&client_stats->num_calls_finished_with_drop_for_rate_limiting); |
||||||
|
atomic_get_and_reset_counter( |
||||||
|
num_calls_finished_with_drop_for_load_balancing, |
||||||
|
&client_stats->num_calls_finished_with_drop_for_load_balancing); |
||||||
|
atomic_get_and_reset_counter( |
||||||
|
num_calls_finished_with_client_failed_to_send, |
||||||
|
&client_stats->num_calls_finished_with_client_failed_to_send); |
||||||
|
atomic_get_and_reset_counter( |
||||||
|
num_calls_finished_known_received, |
||||||
|
&client_stats->num_calls_finished_known_received); |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2017, Google Inc. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* * Redistributions in binary form must reproduce the above |
||||||
|
* copyright notice, this list of conditions and the following disclaimer |
||||||
|
* in the documentation and/or other materials provided with the |
||||||
|
* distribution. |
||||||
|
* * Neither the name of Google Inc. nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H |
||||||
|
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H |
||||||
|
|
||||||
|
#include <stdbool.h> |
||||||
|
|
||||||
|
#include <grpc/impl/codegen/grpc_types.h> |
||||||
|
|
||||||
|
typedef struct grpc_grpclb_client_stats grpc_grpclb_client_stats; |
||||||
|
|
||||||
|
grpc_grpclb_client_stats* grpc_grpclb_client_stats_create(); |
||||||
|
grpc_grpclb_client_stats* grpc_grpclb_client_stats_ref( |
||||||
|
grpc_grpclb_client_stats* client_stats); |
||||||
|
void grpc_grpclb_client_stats_unref(grpc_grpclb_client_stats* client_stats); |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_add_call_started( |
||||||
|
grpc_grpclb_client_stats* client_stats); |
||||||
|
void grpc_grpclb_client_stats_add_call_finished( |
||||||
|
bool finished_with_drop_for_rate_limiting, |
||||||
|
bool finished_with_drop_for_load_balancing, |
||||||
|
bool finished_with_client_failed_to_send, bool finished_known_received, |
||||||
|
grpc_grpclb_client_stats* client_stats); |
||||||
|
|
||||||
|
void grpc_grpclb_client_stats_get( |
||||||
|
grpc_grpclb_client_stats* client_stats, int64_t* num_calls_started, |
||||||
|
int64_t* num_calls_finished, |
||||||
|
int64_t* num_calls_finished_with_drop_for_rate_limiting, |
||||||
|
int64_t* num_calls_finished_with_drop_for_load_balancing, |
||||||
|
int64_t* num_calls_finished_with_client_failed_to_send, |
||||||
|
int64_t* num_calls_finished_known_received); |
||||||
|
|
||||||
|
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \ |
||||||
|
*/ |
@ -1,86 +0,0 @@ |
|||||||
/*
|
|
||||||
* |
|
||||||
* Copyright 2015, Google Inc. |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* * Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following disclaimer |
|
||||||
* in the documentation and/or other materials provided with the |
|
||||||
* distribution. |
|
||||||
* * Neither the name of Google Inc. nor the names of its |
|
||||||
* contributors may be used to endorse or promote products derived from |
|
||||||
* this software without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
* |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_ |
|
||||||
#define NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_ |
|
||||||
#include <nan.h> |
|
||||||
|
|
||||||
#include "grpc/grpc.h" |
|
||||||
|
|
||||||
namespace grpc { |
|
||||||
namespace node { |
|
||||||
|
|
||||||
/* A worker that asynchronously calls completion_queue_next, and queues onto the
|
|
||||||
node event loop a call to the function stored in the event's tag. */ |
|
||||||
class CompletionQueueAsyncWorker : public Nan::AsyncWorker { |
|
||||||
public: |
|
||||||
CompletionQueueAsyncWorker(); |
|
||||||
|
|
||||||
~CompletionQueueAsyncWorker(); |
|
||||||
/* Calls completion_queue_next with the provided deadline, and stores the
|
|
||||||
event if there was one or sets an error message if there was not */ |
|
||||||
void Execute(); |
|
||||||
|
|
||||||
/* Returns the completion queue attached to this class */ |
|
||||||
static grpc_completion_queue *GetQueue(); |
|
||||||
|
|
||||||
/* Convenience function to create a worker with the given arguments and queue
|
|
||||||
it to run asynchronously */ |
|
||||||
static void Next(); |
|
||||||
|
|
||||||
/* Initialize the CompletionQueueAsyncWorker class */ |
|
||||||
static void Init(v8::Local<v8::Object> exports); |
|
||||||
|
|
||||||
protected: |
|
||||||
/* Called when Execute has succeeded (completed without setting an error
|
|
||||||
message). Calls the saved callback with the event that came from |
|
||||||
completion_queue_next */ |
|
||||||
void HandleOKCallback(); |
|
||||||
|
|
||||||
void HandleErrorCallback(); |
|
||||||
|
|
||||||
private: |
|
||||||
grpc_event result; |
|
||||||
|
|
||||||
static grpc_completion_queue *queue; |
|
||||||
|
|
||||||
// Number of grpc_completion_queue_next calls in the thread pool
|
|
||||||
static int current_threads; |
|
||||||
// Number of grpc_completion_queue_next calls waiting to enter the thread pool
|
|
||||||
static int waiting_next_calls; |
|
||||||
}; |
|
||||||
|
|
||||||
} // namespace node
|
|
||||||
} // namespace grpc
|
|
||||||
|
|
||||||
#endif // NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_
|
|
@ -1,180 +0,0 @@ |
|||||||
/*
|
|
||||||
* |
|
||||||
* Copyright 2015, Google Inc. |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* * Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following disclaimer |
|
||||||
* in the documentation and/or other materials provided with the |
|
||||||
* distribution. |
|
||||||
* * Neither the name of Google Inc. nor the names of its |
|
||||||
* contributors may be used to endorse or promote products derived from |
|
||||||
* this software without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
* |
|
||||||
*/ |
|
||||||
|
|
||||||
/* I don't like using #ifndef, but I don't see a better way to do this */ |
|
||||||
#ifndef GRPC_UV |
|
||||||
|
|
||||||
#include <nan.h> |
|
||||||
#include <node.h> |
|
||||||
|
|
||||||
#include "call.h" |
|
||||||
#include "completion_queue.h" |
|
||||||
#include "grpc/grpc.h" |
|
||||||
#include "grpc/support/log.h" |
|
||||||
#include "grpc/support/time.h" |
|
||||||
|
|
||||||
namespace grpc { |
|
||||||
namespace node { |
|
||||||
|
|
||||||
namespace { |
|
||||||
|
|
||||||
/* A worker that asynchronously calls completion_queue_next, and queues onto the
|
|
||||||
node event loop a call to the function stored in the event's tag. */ |
|
||||||
class CompletionQueueAsyncWorker : public Nan::AsyncWorker { |
|
||||||
public: |
|
||||||
CompletionQueueAsyncWorker(); |
|
||||||
|
|
||||||
~CompletionQueueAsyncWorker(); |
|
||||||
/* Calls completion_queue_next with the provided deadline, and stores the
|
|
||||||
event if there was one or sets an error message if there was not */ |
|
||||||
void Execute(); |
|
||||||
|
|
||||||
/* Returns the completion queue attached to this class */ |
|
||||||
static grpc_completion_queue *GetQueue(); |
|
||||||
|
|
||||||
/* Convenience function to create a worker with the given arguments and queue
|
|
||||||
it to run asynchronously */ |
|
||||||
static void Next(); |
|
||||||
|
|
||||||
/* Initialize the CompletionQueueAsyncWorker class */ |
|
||||||
static void Init(v8::Local<v8::Object> exports); |
|
||||||
|
|
||||||
protected: |
|
||||||
/* Called when Execute has succeeded (completed without setting an error
|
|
||||||
message). Calls the saved callback with the event that came from |
|
||||||
completion_queue_next */ |
|
||||||
void HandleOKCallback(); |
|
||||||
|
|
||||||
void HandleErrorCallback(); |
|
||||||
|
|
||||||
private: |
|
||||||
static void TryAddWorker(); |
|
||||||
|
|
||||||
grpc_event result; |
|
||||||
|
|
||||||
static grpc_completion_queue *queue; |
|
||||||
|
|
||||||
// Number of grpc_completion_queue_next calls in the thread pool
|
|
||||||
static int current_threads; |
|
||||||
// Number of grpc_completion_queue_next calls waiting to enter the thread pool
|
|
||||||
static int waiting_next_calls; |
|
||||||
}; |
|
||||||
|
|
||||||
const int max_queue_threads = 2; |
|
||||||
|
|
||||||
using v8::Function; |
|
||||||
using v8::Local; |
|
||||||
using v8::Object; |
|
||||||
using v8::Value; |
|
||||||
|
|
||||||
grpc_completion_queue *CompletionQueueAsyncWorker::queue; |
|
||||||
|
|
||||||
// Invariants: current_threads <= max_queue_threads
|
|
||||||
// (current_threads == max_queue_threads) || (waiting_next_calls == 0)
|
|
||||||
|
|
||||||
int CompletionQueueAsyncWorker::current_threads; |
|
||||||
int CompletionQueueAsyncWorker::waiting_next_calls; |
|
||||||
|
|
||||||
CompletionQueueAsyncWorker::CompletionQueueAsyncWorker() |
|
||||||
: Nan::AsyncWorker(NULL) {} |
|
||||||
|
|
||||||
CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {} |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::Execute() { |
|
||||||
result = grpc_completion_queue_next(queue, gpr_inf_future(GPR_CLOCK_REALTIME), |
|
||||||
NULL); |
|
||||||
if (!result.success) { |
|
||||||
SetErrorMessage("The async function encountered an error"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; } |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::TryAddWorker() { |
|
||||||
if (current_threads < max_queue_threads && waiting_next_calls > 0) { |
|
||||||
current_threads += 1; |
|
||||||
waiting_next_calls -= 1; |
|
||||||
CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker(); |
|
||||||
Nan::AsyncQueueWorker(worker); |
|
||||||
} |
|
||||||
GPR_ASSERT(current_threads <= max_queue_threads); |
|
||||||
GPR_ASSERT((current_threads == max_queue_threads) || |
|
||||||
(waiting_next_calls == 0)); |
|
||||||
} |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::Next() { |
|
||||||
waiting_next_calls += 1; |
|
||||||
TryAddWorker(); |
|
||||||
} |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::Init(Local<Object> exports) { |
|
||||||
Nan::HandleScope scope; |
|
||||||
current_threads = 0; |
|
||||||
waiting_next_calls = 0; |
|
||||||
queue = grpc_completion_queue_create_for_next(NULL); |
|
||||||
} |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::HandleOKCallback() { |
|
||||||
Nan::HandleScope scope; |
|
||||||
current_threads -= 1; |
|
||||||
TryAddWorker(); |
|
||||||
CompleteTag(result.tag, NULL); |
|
||||||
|
|
||||||
DestroyTag(result.tag); |
|
||||||
} |
|
||||||
|
|
||||||
void CompletionQueueAsyncWorker::HandleErrorCallback() { |
|
||||||
Nan::HandleScope scope; |
|
||||||
current_threads -= 1; |
|
||||||
TryAddWorker(); |
|
||||||
CompleteTag(result.tag, ErrorMessage()); |
|
||||||
|
|
||||||
DestroyTag(result.tag); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
grpc_completion_queue *GetCompletionQueue() { |
|
||||||
return CompletionQueueAsyncWorker::GetQueue(); |
|
||||||
} |
|
||||||
|
|
||||||
void CompletionQueueNext() { CompletionQueueAsyncWorker::Next(); } |
|
||||||
|
|
||||||
void CompletionQueueInit(Local<Object> exports) { |
|
||||||
CompletionQueueAsyncWorker::Init(exports); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace node
|
|
||||||
} // namespace grpc
|
|
||||||
|
|
||||||
#endif /* GRPC_UV */ |
|
@ -1,120 +0,0 @@ |
|||||||
/*
|
|
||||||
* |
|
||||||
* Copyright 2017, Google Inc. |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or without |
|
||||||
* modification, are permitted provided that the following conditions are |
|
||||||
* met: |
|
||||||
* |
|
||||||
* * Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* * Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following disclaimer |
|
||||||
* in the documentation and/or other materials provided with the |
|
||||||
* distribution. |
|
||||||
* * Neither the name of Google Inc. nor the names of its |
|
||||||
* contributors may be used to endorse or promote products derived from |
|
||||||
* this software without specific prior written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
* |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef GRPC_UV |
|
||||||
|
|
||||||
#include "server.h" |
|
||||||
|
|
||||||
#include <nan.h> |
|
||||||
#include <node.h> |
|
||||||
#include "grpc/grpc.h" |
|
||||||
#include "grpc/support/time.h" |
|
||||||
|
|
||||||
#include "call.h" |
|
||||||
#include "completion_queue.h" |
|
||||||
|
|
||||||
namespace grpc { |
|
||||||
namespace node { |
|
||||||
|
|
||||||
using Nan::Callback; |
|
||||||
using Nan::MaybeLocal; |
|
||||||
|
|
||||||
using v8::External; |
|
||||||
using v8::Function; |
|
||||||
using v8::FunctionTemplate; |
|
||||||
using v8::Local; |
|
||||||
using v8::Object; |
|
||||||
using v8::Value; |
|
||||||
|
|
||||||
static Callback *shutdown_callback = NULL; |
|
||||||
|
|
||||||
class ServerShutdownOp : public Op { |
|
||||||
public: |
|
||||||
ServerShutdownOp(grpc_server *server) : server(server) {} |
|
||||||
|
|
||||||
~ServerShutdownOp() {} |
|
||||||
|
|
||||||
Local<Value> GetNodeValue() const { return Nan::Null(); } |
|
||||||
|
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) { return true; } |
|
||||||
bool IsFinalOp() { return false; } |
|
||||||
void OnComplete(bool success) { |
|
||||||
/* Because cancel_all_calls was called, we assume that shutdown_and_notify
|
|
||||||
completes successfully */ |
|
||||||
grpc_server_destroy(server); |
|
||||||
} |
|
||||||
|
|
||||||
grpc_server *server; |
|
||||||
|
|
||||||
protected: |
|
||||||
std::string GetTypeString() const { return "shutdown"; } |
|
||||||
}; |
|
||||||
|
|
||||||
Server::Server(grpc_server *server) : wrapped_server(server) {} |
|
||||||
|
|
||||||
Server::~Server() { this->ShutdownServer(); } |
|
||||||
|
|
||||||
NAN_METHOD(ServerShutdownCallback) { |
|
||||||
if (!info[0]->IsNull()) { |
|
||||||
return Nan::ThrowError("forceShutdown failed somehow"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void Server::ShutdownServer() { |
|
||||||
Nan::HandleScope scope; |
|
||||||
if (this->wrapped_server != NULL) { |
|
||||||
if (shutdown_callback == NULL) { |
|
||||||
Local<FunctionTemplate> callback_tpl = |
|
||||||
Nan::New<FunctionTemplate>(ServerShutdownCallback); |
|
||||||
shutdown_callback = |
|
||||||
new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked()); |
|
||||||
} |
|
||||||
|
|
||||||
ServerShutdownOp *op = new ServerShutdownOp(this->wrapped_server); |
|
||||||
unique_ptr<OpVec> ops(new OpVec()); |
|
||||||
ops->push_back(unique_ptr<Op>(op)); |
|
||||||
|
|
||||||
grpc_server_shutdown_and_notify( |
|
||||||
this->wrapped_server, GetCompletionQueue(), |
|
||||||
new struct tag(new Callback(**shutdown_callback), ops.release(), NULL, |
|
||||||
Nan::Null())); |
|
||||||
grpc_server_cancel_all_calls(this->wrapped_server); |
|
||||||
CompletionQueueNext(); |
|
||||||
this->wrapped_server = NULL; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace grpc
|
|
||||||
} // namespace node
|
|
||||||
|
|
||||||
#endif /* GRPC_UV */ |
|
@ -0,0 +1,639 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2017, Google Inc. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* * Redistributions in binary form must reproduce the above |
||||||
|
* copyright notice, this list of conditions and the following disclaimer |
||||||
|
* in the documentation and/or other materials provided with the |
||||||
|
* distribution. |
||||||
|
* * Neither the name of Google Inc. nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <memory> |
||||||
|
#include <mutex> |
||||||
|
#include <sstream> |
||||||
|
#include <thread> |
||||||
|
|
||||||
|
#include <grpc++/channel.h> |
||||||
|
#include <grpc++/client_context.h> |
||||||
|
#include <grpc++/create_channel.h> |
||||||
|
#include <grpc++/server.h> |
||||||
|
#include <grpc++/server_builder.h> |
||||||
|
#include <grpc/grpc.h> |
||||||
|
#include <grpc/support/alloc.h> |
||||||
|
#include <grpc/support/log.h> |
||||||
|
#include <grpc/support/string_util.h> |
||||||
|
#include <grpc/support/thd.h> |
||||||
|
#include <grpc/support/time.h> |
||||||
|
#include <gtest/gtest.h> |
||||||
|
|
||||||
|
extern "C" { |
||||||
|
#include "src/core/lib/iomgr/sockaddr.h" |
||||||
|
#include "test/core/end2end/fake_resolver.h" |
||||||
|
} |
||||||
|
|
||||||
|
#include "test/core/util/port.h" |
||||||
|
#include "test/core/util/test_config.h" |
||||||
|
#include "test/cpp/end2end/test_service_impl.h" |
||||||
|
|
||||||
|
#include "src/proto/grpc/lb/v1/load_balancer.grpc.pb.h" |
||||||
|
#include "src/proto/grpc/testing/echo.grpc.pb.h" |
||||||
|
|
||||||
|
// TODO(dgq): Other scenarios in need of testing:
|
||||||
|
// - Send a serverlist with faulty ip:port addresses (port > 2^16, etc).
|
||||||
|
// - Test reception of invalid serverlist
|
||||||
|
// - Test pinging
|
||||||
|
// - Test against a non-LB server.
|
||||||
|
// - Random LB server closing the stream unexpectedly.
|
||||||
|
// - Test using DNS-resolvable names (localhost?)
|
||||||
|
// - Test handling of creation of faulty RR instance by having the LB return a
|
||||||
|
// serverlist with non-existent backends after having initially returned a
|
||||||
|
// valid one.
|
||||||
|
//
|
||||||
|
// Findings from end to end testing to be covered here:
|
||||||
|
// - Handling of LB servers restart, including reconnection after backing-off
|
||||||
|
// retries.
|
||||||
|
// - Destruction of load balanced channel (and therefore of grpclb instance)
|
||||||
|
// while:
|
||||||
|
// 1) the internal LB call is still active. This should work by virtue
|
||||||
|
// of the weak reference the LB call holds. The call should be terminated as
|
||||||
|
// part of the grpclb shutdown process.
|
||||||
|
// 2) the retry timer is active. Again, the weak reference it holds should
|
||||||
|
// prevent a premature call to \a glb_destroy.
|
||||||
|
// - Restart of backend servers with no changes to serverlist. This exercises
|
||||||
|
// the RR handover mechanism.
|
||||||
|
|
||||||
|
using std::chrono::system_clock; |
||||||
|
|
||||||
|
using grpc::lb::v1::LoadBalanceResponse; |
||||||
|
using grpc::lb::v1::LoadBalanceRequest; |
||||||
|
using grpc::lb::v1::LoadBalancer; |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
namespace testing { |
||||||
|
namespace { |
||||||
|
|
||||||
|
template <typename ServiceType> |
||||||
|
class CountedService : public ServiceType { |
||||||
|
public: |
||||||
|
int request_count() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
return request_count_; |
||||||
|
} |
||||||
|
|
||||||
|
int response_count() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
return response_count_; |
||||||
|
} |
||||||
|
|
||||||
|
void IncreaseResponseCount() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
++response_count_; |
||||||
|
} |
||||||
|
void IncreaseRequestCount() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
++request_count_; |
||||||
|
} |
||||||
|
|
||||||
|
protected: |
||||||
|
std::mutex mu_; |
||||||
|
|
||||||
|
private: |
||||||
|
int request_count_ = 0; |
||||||
|
int response_count_ = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
using BackendService = CountedService<TestServiceImpl>; |
||||||
|
using BalancerService = CountedService<LoadBalancer::Service>; |
||||||
|
|
||||||
|
class BackendServiceImpl : public BackendService { |
||||||
|
public: |
||||||
|
BackendServiceImpl() {} |
||||||
|
|
||||||
|
Status Echo(ServerContext* context, const EchoRequest* request, |
||||||
|
EchoResponse* response) override { |
||||||
|
IncreaseRequestCount(); |
||||||
|
const auto status = TestServiceImpl::Echo(context, request, response); |
||||||
|
IncreaseResponseCount(); |
||||||
|
return status; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
grpc::string Ip4ToPackedString(const char* ip_str) { |
||||||
|
struct in_addr ip4; |
||||||
|
GPR_ASSERT(inet_pton(AF_INET, ip_str, &ip4) == 1); |
||||||
|
return grpc::string(reinterpret_cast<const char*>(&ip4), sizeof(ip4)); |
||||||
|
} |
||||||
|
|
||||||
|
struct ClientStats { |
||||||
|
size_t num_calls_started = 0; |
||||||
|
size_t num_calls_finished = 0; |
||||||
|
size_t num_calls_finished_with_drop_for_rate_limiting = 0; |
||||||
|
size_t num_calls_finished_with_drop_for_load_balancing = 0; |
||||||
|
size_t num_calls_finished_with_client_failed_to_send = 0; |
||||||
|
size_t num_calls_finished_known_received = 0; |
||||||
|
|
||||||
|
ClientStats& operator+=(const ClientStats& other) { |
||||||
|
num_calls_started += other.num_calls_started; |
||||||
|
num_calls_finished += other.num_calls_finished; |
||||||
|
num_calls_finished_with_drop_for_rate_limiting += |
||||||
|
other.num_calls_finished_with_drop_for_rate_limiting; |
||||||
|
num_calls_finished_with_drop_for_load_balancing += |
||||||
|
other.num_calls_finished_with_drop_for_load_balancing; |
||||||
|
num_calls_finished_with_client_failed_to_send += |
||||||
|
other.num_calls_finished_with_client_failed_to_send; |
||||||
|
num_calls_finished_known_received += |
||||||
|
other.num_calls_finished_known_received; |
||||||
|
return *this; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
class BalancerServiceImpl : public BalancerService { |
||||||
|
public: |
||||||
|
using Stream = ServerReaderWriter<LoadBalanceResponse, LoadBalanceRequest>; |
||||||
|
using ResponseDelayPair = std::pair<LoadBalanceResponse, int>; |
||||||
|
|
||||||
|
explicit BalancerServiceImpl(int client_load_reporting_interval_seconds) |
||||||
|
: client_load_reporting_interval_seconds_( |
||||||
|
client_load_reporting_interval_seconds), |
||||||
|
shutdown_(false) {} |
||||||
|
|
||||||
|
Status BalanceLoad(ServerContext* context, Stream* stream) override { |
||||||
|
LoadBalanceRequest request; |
||||||
|
stream->Read(&request); |
||||||
|
IncreaseRequestCount(); |
||||||
|
gpr_log(GPR_INFO, "LB: recv msg '%s'", request.DebugString().c_str()); |
||||||
|
|
||||||
|
if (client_load_reporting_interval_seconds_ > 0) { |
||||||
|
LoadBalanceResponse initial_response; |
||||||
|
initial_response.mutable_initial_response() |
||||||
|
->mutable_client_stats_report_interval() |
||||||
|
->set_seconds(client_load_reporting_interval_seconds_); |
||||||
|
stream->Write(initial_response); |
||||||
|
} |
||||||
|
|
||||||
|
std::vector<ResponseDelayPair> responses_and_delays; |
||||||
|
{ |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
responses_and_delays = responses_and_delays_; |
||||||
|
} |
||||||
|
for (const auto& response_and_delay : responses_and_delays) { |
||||||
|
if (shutdown_) break; |
||||||
|
SendResponse(stream, response_and_delay.first, response_and_delay.second); |
||||||
|
} |
||||||
|
|
||||||
|
if (client_load_reporting_interval_seconds_ > 0) { |
||||||
|
request.Clear(); |
||||||
|
stream->Read(&request); |
||||||
|
gpr_log(GPR_INFO, "LB: recv client load report msg: '%s'", |
||||||
|
request.DebugString().c_str()); |
||||||
|
GPR_ASSERT(request.has_client_stats()); |
||||||
|
client_stats_.num_calls_started += |
||||||
|
request.client_stats().num_calls_started(); |
||||||
|
client_stats_.num_calls_finished += |
||||||
|
request.client_stats().num_calls_finished(); |
||||||
|
client_stats_.num_calls_finished_with_drop_for_rate_limiting += |
||||||
|
request.client_stats() |
||||||
|
.num_calls_finished_with_drop_for_rate_limiting(); |
||||||
|
client_stats_.num_calls_finished_with_drop_for_load_balancing += |
||||||
|
request.client_stats() |
||||||
|
.num_calls_finished_with_drop_for_load_balancing(); |
||||||
|
client_stats_.num_calls_finished_with_client_failed_to_send += |
||||||
|
request.client_stats() |
||||||
|
.num_calls_finished_with_client_failed_to_send(); |
||||||
|
client_stats_.num_calls_finished_known_received += |
||||||
|
request.client_stats().num_calls_finished_known_received(); |
||||||
|
std::lock_guard<std::mutex> lock(mu_); |
||||||
|
cond_.notify_one(); |
||||||
|
} |
||||||
|
|
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
void add_response(const LoadBalanceResponse& response, int send_after_ms) { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
responses_and_delays_.push_back(std::make_pair(response, send_after_ms)); |
||||||
|
} |
||||||
|
|
||||||
|
void Shutdown() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
shutdown_ = true; |
||||||
|
} |
||||||
|
|
||||||
|
static LoadBalanceResponse BuildResponseForBackends( |
||||||
|
const std::vector<int>& backend_ports) { |
||||||
|
LoadBalanceResponse response; |
||||||
|
for (const int backend_port : backend_ports) { |
||||||
|
auto* server = response.mutable_server_list()->add_servers(); |
||||||
|
server->set_ip_address(Ip4ToPackedString("127.0.0.1")); |
||||||
|
server->set_port(backend_port); |
||||||
|
} |
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
const ClientStats& WaitForLoadReport() { |
||||||
|
std::unique_lock<std::mutex> lock(mu_); |
||||||
|
cond_.wait(lock); |
||||||
|
return client_stats_; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
void SendResponse(Stream* stream, const LoadBalanceResponse& response, |
||||||
|
int delay_ms) { |
||||||
|
gpr_log(GPR_INFO, "LB: sleeping for %d ms...", delay_ms); |
||||||
|
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), |
||||||
|
gpr_time_from_millis(delay_ms, GPR_TIMESPAN))); |
||||||
|
gpr_log(GPR_INFO, "LB: Woke up! Sending response '%s'", |
||||||
|
response.DebugString().c_str()); |
||||||
|
stream->Write(response); |
||||||
|
IncreaseResponseCount(); |
||||||
|
} |
||||||
|
|
||||||
|
const int client_load_reporting_interval_seconds_; |
||||||
|
std::vector<ResponseDelayPair> responses_and_delays_; |
||||||
|
std::mutex mu_; |
||||||
|
std::condition_variable cond_; |
||||||
|
ClientStats client_stats_; |
||||||
|
bool shutdown_; |
||||||
|
}; |
||||||
|
|
||||||
|
class GrpclbEnd2endTest : public ::testing::Test { |
||||||
|
protected: |
||||||
|
GrpclbEnd2endTest(int num_backends, int num_balancers, |
||||||
|
int client_load_reporting_interval_seconds) |
||||||
|
: server_host_("localhost"), |
||||||
|
num_backends_(num_backends), |
||||||
|
num_balancers_(num_balancers), |
||||||
|
client_load_reporting_interval_seconds_( |
||||||
|
client_load_reporting_interval_seconds) {} |
||||||
|
|
||||||
|
void SetUp() override { |
||||||
|
response_generator_ = grpc_fake_resolver_response_generator_create(); |
||||||
|
// Start the backends.
|
||||||
|
for (size_t i = 0; i < num_backends_; ++i) { |
||||||
|
backends_.emplace_back(new BackendServiceImpl()); |
||||||
|
backend_servers_.emplace_back(ServerThread<BackendService>( |
||||||
|
"backend", server_host_, backends_.back().get())); |
||||||
|
} |
||||||
|
// Start the load balancers.
|
||||||
|
for (size_t i = 0; i < num_balancers_; ++i) { |
||||||
|
balancers_.emplace_back( |
||||||
|
new BalancerServiceImpl(client_load_reporting_interval_seconds_)); |
||||||
|
balancer_servers_.emplace_back(ServerThread<BalancerService>( |
||||||
|
"balancer", server_host_, balancers_.back().get())); |
||||||
|
} |
||||||
|
ResetStub(); |
||||||
|
std::vector<AddressData> addresses; |
||||||
|
for (size_t i = 0; i < balancer_servers_.size(); ++i) { |
||||||
|
addresses.emplace_back(AddressData{balancer_servers_[i].port_, true, ""}); |
||||||
|
} |
||||||
|
SetNextResolution(addresses); |
||||||
|
} |
||||||
|
|
||||||
|
void TearDown() override { |
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
backend_servers_[i].Shutdown(); |
||||||
|
} |
||||||
|
for (size_t i = 0; i < balancers_.size(); ++i) { |
||||||
|
balancers_[i]->Shutdown(); |
||||||
|
balancer_servers_[i].Shutdown(); |
||||||
|
} |
||||||
|
grpc_fake_resolver_response_generator_unref(response_generator_); |
||||||
|
} |
||||||
|
|
||||||
|
void ResetStub() { |
||||||
|
ChannelArguments args; |
||||||
|
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, |
||||||
|
response_generator_); |
||||||
|
std::ostringstream uri; |
||||||
|
uri << "test:///servername_not_used"; |
||||||
|
channel_ = |
||||||
|
CreateCustomChannel(uri.str(), InsecureChannelCredentials(), args); |
||||||
|
stub_ = grpc::testing::EchoTestService::NewStub(channel_); |
||||||
|
} |
||||||
|
|
||||||
|
ClientStats WaitForLoadReports() { |
||||||
|
ClientStats client_stats; |
||||||
|
for (const auto& balancer : balancers_) { |
||||||
|
client_stats += balancer->WaitForLoadReport(); |
||||||
|
} |
||||||
|
return client_stats; |
||||||
|
} |
||||||
|
|
||||||
|
struct AddressData { |
||||||
|
int port; |
||||||
|
bool is_balancer; |
||||||
|
grpc::string balancer_name; |
||||||
|
}; |
||||||
|
|
||||||
|
void SetNextResolution(const std::vector<AddressData>& address_data) { |
||||||
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||||
|
grpc_lb_addresses* addresses = |
||||||
|
grpc_lb_addresses_create(address_data.size(), nullptr); |
||||||
|
for (size_t i = 0; i < address_data.size(); ++i) { |
||||||
|
char* lb_uri_str; |
||||||
|
gpr_asprintf(&lb_uri_str, "ipv4:127.0.0.1:%d", address_data[i].port); |
||||||
|
grpc_uri* lb_uri = grpc_uri_parse(&exec_ctx, lb_uri_str, true); |
||||||
|
GPR_ASSERT(lb_uri != nullptr); |
||||||
|
grpc_lb_addresses_set_address_from_uri( |
||||||
|
addresses, i, lb_uri, address_data[i].is_balancer, |
||||||
|
address_data[i].balancer_name.c_str(), nullptr); |
||||||
|
grpc_uri_destroy(lb_uri); |
||||||
|
gpr_free(lb_uri_str); |
||||||
|
} |
||||||
|
grpc_arg fake_addresses = grpc_lb_addresses_create_channel_arg(addresses); |
||||||
|
grpc_channel_args fake_result = {1, &fake_addresses}; |
||||||
|
grpc_fake_resolver_response_generator_set_response( |
||||||
|
&exec_ctx, response_generator_, &fake_result); |
||||||
|
grpc_lb_addresses_destroy(&exec_ctx, addresses); |
||||||
|
grpc_exec_ctx_finish(&exec_ctx); |
||||||
|
} |
||||||
|
|
||||||
|
const std::vector<int> GetBackendPorts() const { |
||||||
|
std::vector<int> backend_ports; |
||||||
|
for (const auto& bs : backend_servers_) { |
||||||
|
backend_ports.push_back(bs.port_); |
||||||
|
} |
||||||
|
return backend_ports; |
||||||
|
} |
||||||
|
|
||||||
|
void ScheduleResponseForBalancer(size_t i, |
||||||
|
const LoadBalanceResponse& response, |
||||||
|
int delay_ms) { |
||||||
|
balancers_.at(i)->add_response(response, delay_ms); |
||||||
|
} |
||||||
|
|
||||||
|
std::vector<std::pair<Status, EchoResponse>> SendRpc(const string& message, |
||||||
|
int num_rpcs, |
||||||
|
int timeout_ms = 1000) { |
||||||
|
std::vector<std::pair<Status, EchoResponse>> results; |
||||||
|
EchoRequest request; |
||||||
|
EchoResponse response; |
||||||
|
request.set_message(message); |
||||||
|
for (int i = 0; i < num_rpcs; i++) { |
||||||
|
ClientContext context; |
||||||
|
context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms)); |
||||||
|
Status status = stub_->Echo(&context, request, &response); |
||||||
|
results.push_back(std::make_pair(status, response)); |
||||||
|
} |
||||||
|
return results; |
||||||
|
} |
||||||
|
|
||||||
|
template <typename T> |
||||||
|
struct ServerThread { |
||||||
|
explicit ServerThread(const grpc::string& type, |
||||||
|
const grpc::string& server_host, T* service) |
||||||
|
: type_(type), service_(service) { |
||||||
|
port_ = grpc_pick_unused_port_or_die(); |
||||||
|
gpr_log(GPR_INFO, "starting %s server on port %d", type_.c_str(), port_); |
||||||
|
std::mutex mu; |
||||||
|
std::condition_variable cond; |
||||||
|
thread_.reset(new std::thread( |
||||||
|
std::bind(&ServerThread::Start, this, server_host, &mu, &cond))); |
||||||
|
std::unique_lock<std::mutex> lock(mu); |
||||||
|
cond.wait(lock); |
||||||
|
gpr_log(GPR_INFO, "%s server startup complete", type_.c_str()); |
||||||
|
} |
||||||
|
|
||||||
|
void Start(const grpc::string& server_host, std::mutex* mu, |
||||||
|
std::condition_variable* cond) { |
||||||
|
std::ostringstream server_address; |
||||||
|
server_address << server_host << ":" << port_; |
||||||
|
ServerBuilder builder; |
||||||
|
builder.AddListeningPort(server_address.str(), |
||||||
|
InsecureServerCredentials()); |
||||||
|
builder.RegisterService(service_); |
||||||
|
server_ = builder.BuildAndStart(); |
||||||
|
std::lock_guard<std::mutex> lock(*mu); |
||||||
|
cond->notify_one(); |
||||||
|
} |
||||||
|
|
||||||
|
void Shutdown() { |
||||||
|
gpr_log(GPR_INFO, "%s about to shutdown", type_.c_str()); |
||||||
|
server_->Shutdown(); |
||||||
|
thread_->join(); |
||||||
|
gpr_log(GPR_INFO, "%s shutdown completed", type_.c_str()); |
||||||
|
} |
||||||
|
|
||||||
|
int port_; |
||||||
|
grpc::string type_; |
||||||
|
std::unique_ptr<Server> server_; |
||||||
|
T* service_; |
||||||
|
std::unique_ptr<std::thread> thread_; |
||||||
|
}; |
||||||
|
|
||||||
|
const grpc::string kMessage_ = "Live long and prosper."; |
||||||
|
const grpc::string server_host_; |
||||||
|
const size_t num_backends_; |
||||||
|
const size_t num_balancers_; |
||||||
|
const int client_load_reporting_interval_seconds_; |
||||||
|
std::shared_ptr<Channel> channel_; |
||||||
|
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
||||||
|
|
||||||
|
std::vector<std::unique_ptr<BackendServiceImpl>> backends_; |
||||||
|
std::vector<std::unique_ptr<BalancerServiceImpl>> balancers_; |
||||||
|
|
||||||
|
std::vector<ServerThread<BackendService>> backend_servers_; |
||||||
|
std::vector<ServerThread<BalancerService>> balancer_servers_; |
||||||
|
|
||||||
|
grpc_fake_resolver_response_generator* response_generator_; |
||||||
|
}; |
||||||
|
|
||||||
|
class SingleBalancerTest : public GrpclbEnd2endTest { |
||||||
|
public: |
||||||
|
SingleBalancerTest() : GrpclbEnd2endTest(4, 1, 0) {} |
||||||
|
}; |
||||||
|
|
||||||
|
TEST_F(SingleBalancerTest, Vanilla) { |
||||||
|
ScheduleResponseForBalancer( |
||||||
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); |
||||||
|
// Make sure that trying to connect works without a call.
|
||||||
|
channel_->GetState(true /* try_to_connect */); |
||||||
|
// Start servers and send 100 RPCs per server.
|
||||||
|
const auto& statuses_and_responses = SendRpc(kMessage_, 100 * num_backends_); |
||||||
|
|
||||||
|
for (const auto& status_and_response : statuses_and_responses) { |
||||||
|
EXPECT_TRUE(status_and_response.first.ok()); |
||||||
|
EXPECT_EQ(status_and_response.second.message(), kMessage_); |
||||||
|
} |
||||||
|
|
||||||
|
// Each backend should have gotten 100 requests.
|
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
EXPECT_EQ(100, backend_servers_[i].service_->request_count()); |
||||||
|
} |
||||||
|
// The balancer got a single request.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); |
||||||
|
// and sent a single response.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->response_count()); |
||||||
|
|
||||||
|
// Check LB policy name for the channel.
|
||||||
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
||||||
|
} |
||||||
|
|
||||||
|
TEST_F(SingleBalancerTest, InitiallyEmptyServerlist) { |
||||||
|
const int kServerlistDelayMs = 500 * grpc_test_slowdown_factor(); |
||||||
|
const int kCallDeadlineMs = 1000 * grpc_test_slowdown_factor(); |
||||||
|
|
||||||
|
// First response is an empty serverlist, sent right away.
|
||||||
|
ScheduleResponseForBalancer(0, LoadBalanceResponse(), 0); |
||||||
|
// Send non-empty serverlist only after kServerlistDelayMs
|
||||||
|
ScheduleResponseForBalancer( |
||||||
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), |
||||||
|
kServerlistDelayMs); |
||||||
|
|
||||||
|
const auto t0 = system_clock::now(); |
||||||
|
// Client will block: LB will initially send empty serverlist.
|
||||||
|
const auto& statuses_and_responses = |
||||||
|
SendRpc(kMessage_, num_backends_, kCallDeadlineMs); |
||||||
|
const auto ellapsed_ms = |
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>( |
||||||
|
system_clock::now() - t0); |
||||||
|
// but eventually, the LB sends a serverlist update that allows the call to
|
||||||
|
// proceed. The call delay must be larger than the delay in sending the
|
||||||
|
// populated serverlist but under the call's deadline.
|
||||||
|
EXPECT_GT(ellapsed_ms.count(), kServerlistDelayMs); |
||||||
|
EXPECT_LT(ellapsed_ms.count(), kCallDeadlineMs); |
||||||
|
|
||||||
|
// Each backend should have gotten 1 request.
|
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
EXPECT_EQ(1, backend_servers_[i].service_->request_count()); |
||||||
|
} |
||||||
|
for (const auto& status_and_response : statuses_and_responses) { |
||||||
|
EXPECT_TRUE(status_and_response.first.ok()); |
||||||
|
EXPECT_EQ(status_and_response.second.message(), kMessage_); |
||||||
|
} |
||||||
|
|
||||||
|
// The balancer got a single request.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); |
||||||
|
// and sent two responses.
|
||||||
|
EXPECT_EQ(2, balancer_servers_[0].service_->response_count()); |
||||||
|
|
||||||
|
// Check LB policy name for the channel.
|
||||||
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
||||||
|
} |
||||||
|
|
||||||
|
TEST_F(SingleBalancerTest, RepeatedServerlist) { |
||||||
|
constexpr int kServerlistDelayMs = 100; |
||||||
|
|
||||||
|
// Send a serverlist right away.
|
||||||
|
ScheduleResponseForBalancer( |
||||||
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); |
||||||
|
// ... and the same one a bit later.
|
||||||
|
ScheduleResponseForBalancer( |
||||||
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), |
||||||
|
kServerlistDelayMs); |
||||||
|
|
||||||
|
// Send num_backends/2 requests.
|
||||||
|
auto statuses_and_responses = SendRpc(kMessage_, num_backends_ / 2); |
||||||
|
// only the first half of the backends will receive them.
|
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
if (i < backends_.size() / 2) |
||||||
|
EXPECT_EQ(1, backend_servers_[i].service_->request_count()); |
||||||
|
else |
||||||
|
EXPECT_EQ(0, backend_servers_[i].service_->request_count()); |
||||||
|
} |
||||||
|
EXPECT_EQ(statuses_and_responses.size(), num_backends_ / 2); |
||||||
|
for (const auto& status_and_response : statuses_and_responses) { |
||||||
|
EXPECT_TRUE(status_and_response.first.ok()); |
||||||
|
EXPECT_EQ(status_and_response.second.message(), kMessage_); |
||||||
|
} |
||||||
|
|
||||||
|
// Wait for the (duplicated) serverlist update.
|
||||||
|
gpr_sleep_until(gpr_time_add( |
||||||
|
gpr_now(GPR_CLOCK_REALTIME), |
||||||
|
gpr_time_from_millis(kServerlistDelayMs * 1.1, GPR_TIMESPAN))); |
||||||
|
|
||||||
|
// Verify the LB has sent two responses.
|
||||||
|
EXPECT_EQ(2, balancer_servers_[0].service_->response_count()); |
||||||
|
|
||||||
|
// Some more calls to complete the total number of backends.
|
||||||
|
statuses_and_responses = SendRpc( |
||||||
|
kMessage_, |
||||||
|
num_backends_ / 2 + (num_backends_ & 0x1) /* extra one if num_bes odd */); |
||||||
|
// Because a duplicated serverlist should have no effect, all backends must
|
||||||
|
// have been hit once now.
|
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
EXPECT_EQ(1, backend_servers_[i].service_->request_count()); |
||||||
|
} |
||||||
|
EXPECT_EQ(statuses_and_responses.size(), num_backends_ / 2); |
||||||
|
for (const auto& status_and_response : statuses_and_responses) { |
||||||
|
EXPECT_TRUE(status_and_response.first.ok()); |
||||||
|
EXPECT_EQ(status_and_response.second.message(), kMessage_); |
||||||
|
} |
||||||
|
|
||||||
|
// The balancer got a single request.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); |
||||||
|
// Check LB policy name for the channel.
|
||||||
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
||||||
|
} |
||||||
|
|
||||||
|
class SingleBalancerWithClientLoadReportingTest : public GrpclbEnd2endTest { |
||||||
|
public: |
||||||
|
SingleBalancerWithClientLoadReportingTest() : GrpclbEnd2endTest(4, 1, 2) {} |
||||||
|
}; |
||||||
|
|
||||||
|
TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) { |
||||||
|
ScheduleResponseForBalancer( |
||||||
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); |
||||||
|
// Start servers and send 100 RPCs per server.
|
||||||
|
const auto& statuses_and_responses = SendRpc(kMessage_, 100 * num_backends_); |
||||||
|
|
||||||
|
for (const auto& status_and_response : statuses_and_responses) { |
||||||
|
EXPECT_TRUE(status_and_response.first.ok()); |
||||||
|
EXPECT_EQ(status_and_response.second.message(), kMessage_); |
||||||
|
} |
||||||
|
|
||||||
|
// Each backend should have gotten 100 requests.
|
||||||
|
for (size_t i = 0; i < backends_.size(); ++i) { |
||||||
|
EXPECT_EQ(100, backend_servers_[i].service_->request_count()); |
||||||
|
} |
||||||
|
// The balancer got a single request.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); |
||||||
|
// and sent a single response.
|
||||||
|
EXPECT_EQ(1, balancer_servers_[0].service_->response_count()); |
||||||
|
|
||||||
|
const ClientStats client_stats = WaitForLoadReports(); |
||||||
|
EXPECT_EQ(100 * num_backends_, client_stats.num_calls_started); |
||||||
|
EXPECT_EQ(100 * num_backends_, client_stats.num_calls_finished); |
||||||
|
EXPECT_EQ(0U, client_stats.num_calls_finished_with_drop_for_rate_limiting); |
||||||
|
EXPECT_EQ(0U, client_stats.num_calls_finished_with_drop_for_load_balancing); |
||||||
|
EXPECT_EQ(0U, client_stats.num_calls_finished_with_client_failed_to_send); |
||||||
|
EXPECT_EQ(100 * num_backends_, |
||||||
|
client_stats.num_calls_finished_known_received); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
int main(int argc, char** argv) { |
||||||
|
grpc_init(); |
||||||
|
grpc_test_init(argc, argv); |
||||||
|
grpc_fake_resolver_init(); |
||||||
|
::testing::InitGoogleTest(&argc, argv); |
||||||
|
const auto result = RUN_ALL_TESTS(); |
||||||
|
grpc_shutdown(); |
||||||
|
return result; |
||||||
|
} |
@ -1,41 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
# runtime 23 * 60 mins |
|
||||||
config=asan-trace-cmp runtime=82800 tools/jenkins/run_fuzzer.sh api_fuzzer |
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_client.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,41 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
# runtime 23 * 60 mins |
|
||||||
config=asan-trace-cmp runtime=82800 tools/jenkins/run_fuzzer.sh client_fuzzer |
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,41 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
config=asan-trace-cmp tools/jenkins/run_fuzzer.sh hpack_parser_fuzzer_test |
|
||||||
|
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_http_request.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,41 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
config=asan-trace-cmp tools/jenkins/run_fuzzer.sh http_request_fuzzer_test |
|
||||||
|
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_json.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,40 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
config=asan-trace-cmp tools/jenkins/run_fuzzer.sh nanopb_fuzzer_response_test |
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_server.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
@ -1,41 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
set -ex |
|
||||||
|
|
||||||
# change to grpc repo root |
|
||||||
cd $(dirname $0)/../../.. |
|
||||||
|
|
||||||
git submodule update --init |
|
||||||
|
|
||||||
# download fuzzer docker image from dockerhub |
|
||||||
export DOCKERHUB_ORGANIZATION=grpctesting |
|
||||||
# runtime 23 * 60 mins |
|
||||||
config=asan-trace-cmp runtime=82800 tools/jenkins/run_fuzzer.sh server_fuzzer |
|
@ -1,39 +0,0 @@ |
|||||||
# Copyright 2017, Google Inc. |
|
||||||
# All rights reserved. |
|
||||||
# |
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are |
|
||||||
# met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above |
|
||||||
# copyright notice, this list of conditions and the following disclaimer |
|
||||||
# in the documentation and/or other materials provided with the |
|
||||||
# distribution. |
|
||||||
# * Neither the name of Google Inc. nor the names of its |
|
||||||
# contributors may be used to endorse or promote products derived from |
|
||||||
# this software without specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
# Config file for the internal CI (in protobuf text format) |
|
||||||
|
|
||||||
# Location of the continuous shell script in repository. |
|
||||||
build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_uri.sh" |
|
||||||
timeout_mins: 1440 # 24 hours is the maximum allowed value |
|
||||||
action { |
|
||||||
define_artifacts { |
|
||||||
regex: "git/grpc/fuzzer_output/**" |
|
||||||
} |
|
||||||
} |
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue