Skip to content

Commit fed6a53

Browse files
authored
Merge pull request kmesh-net#888 from bfforever/lb_ospp
Kmesh ads mode cluster add consistent hash lb
2 parents 4b403b2 + 90312f8 commit fed6a53

File tree

15 files changed

+1018
-64
lines changed

15 files changed

+1018
-64
lines changed

api/cluster/cluster.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ message Cluster {
1212
ROUND_ROBIN = 0;
1313
LEAST_REQUEST = 1;
1414
RANDOM = 3;
15+
MAGLEV = 5;
1516
}
1617

1718
core.ApiStatus api_status = 128;

api/route/route_components.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,26 @@ message RouteAction {
3030
// assigned to each cluster.
3131
WeightedCluster weighted_clusters = 3;
3232
}
33+
34+
message HashPolicy {
35+
message Header {
36+
// The name of the request header that will be used to obtain the hash
37+
// key. If the request header is not present, no hash will be produced.
38+
string header_name = 1;
39+
}
40+
41+
oneof policy_specifier {
42+
43+
// Header hash policy.
44+
Header header = 1;
45+
}
46+
}
47+
3348
// the matched prefix (or path) should be swapped with this value.
3449
string prefix_rewrite = 5;
3550
uint32 timeout = 8;
3651
RetryPolicy retry_policy = 9;
52+
repeated HashPolicy hash_policy = 15;
3753
}
3854

3955
message RetryPolicy {

api/v2-c/cluster/cluster.pb-c.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ void cluster__cluster__free_unpacked
5252
assert(message->base.descriptor == &cluster__cluster__descriptor);
5353
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
5454
}
55-
static const ProtobufCEnumValue cluster__cluster__lb_policy__enum_values_by_number[3] =
55+
static const ProtobufCEnumValue cluster__cluster__lb_policy__enum_values_by_number[4] =
5656
{
5757
{ "ROUND_ROBIN", "CLUSTER__CLUSTER__LB_POLICY__ROUND_ROBIN", 0 },
5858
{ "LEAST_REQUEST", "CLUSTER__CLUSTER__LB_POLICY__LEAST_REQUEST", 1 },
5959
{ "RANDOM", "CLUSTER__CLUSTER__LB_POLICY__RANDOM", 3 },
60+
{ "MAGLEV", "CLUSTER__CLUSTER__LB_POLICY__MAGLEV", 5 },
6061
};
6162
static const ProtobufCIntRange cluster__cluster__lb_policy__value_ranges[] = {
62-
{0, 0},{3, 2},{0, 3}
63+
{0, 0},{3, 2},{5, 3},{0, 4}
6364
};
64-
static const ProtobufCEnumValueIndex cluster__cluster__lb_policy__enum_values_by_name[3] =
65+
static const ProtobufCEnumValueIndex cluster__cluster__lb_policy__enum_values_by_name[4] =
6566
{
6667
{ "LEAST_REQUEST", 1 },
68+
{ "MAGLEV", 3 },
6769
{ "RANDOM", 2 },
6870
{ "ROUND_ROBIN", 0 },
6971
};
@@ -74,11 +76,11 @@ const ProtobufCEnumDescriptor cluster__cluster__lb_policy__descriptor =
7476
"LbPolicy",
7577
"Cluster__Cluster__LbPolicy",
7678
"cluster",
77-
3,
79+
4,
7880
cluster__cluster__lb_policy__enum_values_by_number,
79-
3,
81+
4,
8082
cluster__cluster__lb_policy__enum_values_by_name,
81-
2,
83+
3,
8284
cluster__cluster__lb_policy__value_ranges,
8385
NULL,NULL,NULL,NULL /* reserved[1234] */
8486
};

api/v2-c/cluster/cluster.pb-c.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2-c/route/route_components.pb-c.c

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ void route__route_match__free_unpacked
142142
assert(message->base.descriptor == &route__route_match__descriptor);
143143
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
144144
}
145+
void route__route_action__hash_policy__header__init
146+
(Route__RouteAction__HashPolicy__Header *message)
147+
{
148+
static const Route__RouteAction__HashPolicy__Header init_value = ROUTE__ROUTE_ACTION__HASH_POLICY__HEADER__INIT;
149+
*message = init_value;
150+
}
151+
void route__route_action__hash_policy__init
152+
(Route__RouteAction__HashPolicy *message)
153+
{
154+
static const Route__RouteAction__HashPolicy init_value = ROUTE__ROUTE_ACTION__HASH_POLICY__INIT;
155+
*message = init_value;
156+
}
145157
void route__route_action__init
146158
(Route__RouteAction *message)
147159
{
@@ -562,7 +574,83 @@ const ProtobufCMessageDescriptor route__route_match__descriptor =
562574
(ProtobufCMessageInit) route__route_match__init,
563575
NULL,NULL,NULL /* reserved[123] */
564576
};
565-
static const ProtobufCFieldDescriptor route__route_action__field_descriptors[5] =
577+
static const ProtobufCFieldDescriptor route__route_action__hash_policy__header__field_descriptors[1] =
578+
{
579+
{
580+
"header_name",
581+
1,
582+
PROTOBUF_C_LABEL_NONE,
583+
PROTOBUF_C_TYPE_STRING,
584+
0, /* quantifier_offset */
585+
offsetof(Route__RouteAction__HashPolicy__Header, header_name),
586+
NULL,
587+
&protobuf_c_empty_string,
588+
0, /* flags */
589+
0,NULL,NULL /* reserved1,reserved2, etc */
590+
},
591+
};
592+
static const unsigned route__route_action__hash_policy__header__field_indices_by_name[] = {
593+
0, /* field[0] = header_name */
594+
};
595+
static const ProtobufCIntRange route__route_action__hash_policy__header__number_ranges[1 + 1] =
596+
{
597+
{ 1, 0 },
598+
{ 0, 1 }
599+
};
600+
const ProtobufCMessageDescriptor route__route_action__hash_policy__header__descriptor =
601+
{
602+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
603+
"route.RouteAction.HashPolicy.Header",
604+
"Header",
605+
"Route__RouteAction__HashPolicy__Header",
606+
"route",
607+
sizeof(Route__RouteAction__HashPolicy__Header),
608+
1,
609+
route__route_action__hash_policy__header__field_descriptors,
610+
route__route_action__hash_policy__header__field_indices_by_name,
611+
1, route__route_action__hash_policy__header__number_ranges,
612+
(ProtobufCMessageInit) route__route_action__hash_policy__header__init,
613+
NULL,NULL,NULL /* reserved[123] */
614+
};
615+
static const ProtobufCFieldDescriptor route__route_action__hash_policy__field_descriptors[1] =
616+
{
617+
{
618+
"header",
619+
1,
620+
PROTOBUF_C_LABEL_NONE,
621+
PROTOBUF_C_TYPE_MESSAGE,
622+
offsetof(Route__RouteAction__HashPolicy, policy_specifier_case),
623+
offsetof(Route__RouteAction__HashPolicy, header),
624+
&route__route_action__hash_policy__header__descriptor,
625+
NULL,
626+
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
627+
0,NULL,NULL /* reserved1,reserved2, etc */
628+
},
629+
};
630+
static const unsigned route__route_action__hash_policy__field_indices_by_name[] = {
631+
0, /* field[0] = header */
632+
};
633+
static const ProtobufCIntRange route__route_action__hash_policy__number_ranges[1 + 1] =
634+
{
635+
{ 1, 0 },
636+
{ 0, 1 }
637+
};
638+
const ProtobufCMessageDescriptor route__route_action__hash_policy__descriptor =
639+
{
640+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
641+
"route.RouteAction.HashPolicy",
642+
"HashPolicy",
643+
"Route__RouteAction__HashPolicy",
644+
"route",
645+
sizeof(Route__RouteAction__HashPolicy),
646+
1,
647+
route__route_action__hash_policy__field_descriptors,
648+
route__route_action__hash_policy__field_indices_by_name,
649+
1, route__route_action__hash_policy__number_ranges,
650+
(ProtobufCMessageInit) route__route_action__hash_policy__init,
651+
NULL,NULL,NULL /* reserved[123] */
652+
};
653+
static const ProtobufCFieldDescriptor route__route_action__field_descriptors[6] =
566654
{
567655
{
568656
"cluster",
@@ -624,21 +712,35 @@ static const ProtobufCFieldDescriptor route__route_action__field_descriptors[5]
624712
0, /* flags */
625713
0,NULL,NULL /* reserved1,reserved2, etc */
626714
},
715+
{
716+
"hash_policy",
717+
15,
718+
PROTOBUF_C_LABEL_REPEATED,
719+
PROTOBUF_C_TYPE_MESSAGE,
720+
offsetof(Route__RouteAction, n_hash_policy),
721+
offsetof(Route__RouteAction, hash_policy),
722+
&route__route_action__hash_policy__descriptor,
723+
NULL,
724+
0, /* flags */
725+
0,NULL,NULL /* reserved1,reserved2, etc */
726+
},
627727
};
628728
static const unsigned route__route_action__field_indices_by_name[] = {
629729
0, /* field[0] = cluster */
730+
5, /* field[5] = hash_policy */
630731
2, /* field[2] = prefix_rewrite */
631732
4, /* field[4] = retry_policy */
632733
3, /* field[3] = timeout */
633734
1, /* field[1] = weighted_clusters */
634735
};
635-
static const ProtobufCIntRange route__route_action__number_ranges[4 + 1] =
736+
static const ProtobufCIntRange route__route_action__number_ranges[5 + 1] =
636737
{
637738
{ 1, 0 },
638739
{ 3, 1 },
639740
{ 5, 2 },
640741
{ 8, 3 },
641-
{ 0, 5 }
742+
{ 15, 5 },
743+
{ 0, 6 }
642744
};
643745
const ProtobufCMessageDescriptor route__route_action__descriptor =
644746
{
@@ -648,10 +750,10 @@ const ProtobufCMessageDescriptor route__route_action__descriptor =
648750
"Route__RouteAction",
649751
"route",
650752
sizeof(Route__RouteAction),
651-
5,
753+
6,
652754
route__route_action__field_descriptors,
653755
route__route_action__field_indices_by_name,
654-
4, route__route_action__number_ranges,
756+
5, route__route_action__number_ranges,
655757
(ProtobufCMessageInit) route__route_action__init,
656758
NULL,NULL,NULL /* reserved[123] */
657759
};

api/v2-c/route/route_components.pb-c.h

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/cluster/cluster.pb.go

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)