Skip to content

Commit 9bf243e

Browse files
author
Luis Sanchez
committed
[FAB-7054] more flexibility setting Kafka.Version
Synced Kafka version support to match Fabric v1.1. - Made the parsing of Kafka.Version in orderer.yaml more forgiving, and mapping the value to a supported underlying value. - Vendored hashicorp/go-version utility for parsing version strings. - Updated the sarama Kafka client library version to match the version in master. Change-Id: I0e10809cc572ba560995c47718c3fbc8f9866494 Signed-off-by: Luis Sanchez <[email protected]>
1 parent dc8d323 commit 9bf243e

File tree

19 files changed

+1090
-46
lines changed

19 files changed

+1090
-46
lines changed

common/viperutil/config_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,34 @@ func TestKafkaVersionDecode(t *testing.T) {
7777
expected sarama.KafkaVersion
7878
errExpected bool
7979
}{
80+
{"0.8", sarama.KafkaVersion{}, true},
8081
{"0.8.2.0", sarama.V0_8_2_0, false},
8182
{"0.8.2.1", sarama.V0_8_2_1, false},
8283
{"0.8.2.2", sarama.V0_8_2_2, false},
8384
{"0.9.0.0", sarama.V0_9_0_0, false},
85+
{"0.9", sarama.V0_9_0_0, false},
86+
{"0.9.0", sarama.V0_9_0_0, false},
8487
{"0.9.0.1", sarama.V0_9_0_1, false},
88+
{"0.9.0.3", sarama.V0_9_0_1, false},
8589
{"0.10.0.0", sarama.V0_10_0_0, false},
90+
{"0.10", sarama.V0_10_0_0, false},
91+
{"0.10.0", sarama.V0_10_0_0, false},
8692
{"0.10.0.1", sarama.V0_10_0_1, false},
8793
{"0.10.1.0", sarama.V0_10_1_0, false},
88-
{"Unsupported", sarama.KafkaVersion{}, true},
94+
{"0.10.2.0", sarama.V0_10_2_0, false},
95+
{"0.10.2.1", sarama.V0_10_2_0, false},
96+
{"0.10.2.2", sarama.V0_10_2_0, false},
97+
{"0.10.2.3", sarama.V0_10_2_0, false},
98+
{"0.11", sarama.KafkaVersion{}, true},
99+
{"0.11.0", sarama.KafkaVersion{}, true},
100+
{"0.11.0.0", sarama.KafkaVersion{}, true},
101+
{"Malformed", sarama.KafkaVersion{}, true},
89102
}
90103

91104
for _, tc := range testCases {
92105
t.Run(tc.data, func(t *testing.T) {
93106

94-
data := fmt.Sprintf("---\nInner:\n Version: %s", tc.data)
107+
data := fmt.Sprintf("---\nInner:\n Version: '%s'", tc.data)
95108
err := config.ReadConfig(bytes.NewReader([]byte(data)))
96109
if err != nil {
97110
t.Fatalf("Error reading config: %s", err)

common/viperutil/config_util.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/pem"
2121

2222
"github.com/Shopify/sarama"
23+
version "github.com/hashicorp/go-version"
2324
"github.com/hyperledger/fabric/common/flogging"
2425
"github.com/mitchellh/mapstructure"
2526
"github.com/spf13/viper"
@@ -245,31 +246,39 @@ func pemBlocksFromFileDecodeHook() mapstructure.DecodeHookFunc {
245246
}
246247
}
247248

249+
var kafkaVersionConstraints map[sarama.KafkaVersion]version.Constraints
250+
251+
func init() {
252+
kafkaVersionConstraints = make(map[sarama.KafkaVersion]version.Constraints)
253+
kafkaVersionConstraints[sarama.V0_8_2_0], _ = version.NewConstraint(">=0.8.2,<0.8.2.1")
254+
kafkaVersionConstraints[sarama.V0_8_2_1], _ = version.NewConstraint(">=0.8.2.1,<0.8.2.2")
255+
kafkaVersionConstraints[sarama.V0_8_2_2], _ = version.NewConstraint(">=0.8.2.2,<0.9.0.0")
256+
kafkaVersionConstraints[sarama.V0_9_0_0], _ = version.NewConstraint(">=0.9.0.0,<0.9.0.1")
257+
kafkaVersionConstraints[sarama.V0_9_0_1], _ = version.NewConstraint(">=0.9.0.1,<0.10.0.0")
258+
kafkaVersionConstraints[sarama.V0_10_0_0], _ = version.NewConstraint(">=0.10.0.0,<0.10.0.1")
259+
kafkaVersionConstraints[sarama.V0_10_0_1], _ = version.NewConstraint(">=0.10.0.1,<0.10.1.0")
260+
kafkaVersionConstraints[sarama.V0_10_1_0], _ = version.NewConstraint(">=0.10.1.0,<0.10.2.0")
261+
kafkaVersionConstraints[sarama.V0_10_2_0], _ = version.NewConstraint(">=0.10.2.0,<0.11.0.0")
262+
}
263+
248264
func kafkaVersionDecodeHook() mapstructure.DecodeHookFunc {
249265
return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
250266
if f.Kind() != reflect.String || t != reflect.TypeOf(sarama.KafkaVersion{}) {
251267
return data, nil
252268
}
253-
switch data {
254-
case "0.8.2.0":
255-
return sarama.V0_8_2_0, nil
256-
case "0.8.2.1":
257-
return sarama.V0_8_2_1, nil
258-
case "0.8.2.2":
259-
return sarama.V0_8_2_2, nil
260-
case "0.9.0.0":
261-
return sarama.V0_9_0_0, nil
262-
case "0.9.0.1":
263-
return sarama.V0_9_0_1, nil
264-
case "0.10.0.0":
265-
return sarama.V0_10_0_0, nil
266-
case "0.10.0.1":
267-
return sarama.V0_10_0_1, nil
268-
case "0.10.1.0":
269-
return sarama.V0_10_1_0, nil
270-
default:
271-
return nil, fmt.Errorf("Unsupported Kafka version: '%s'", data)
269+
270+
v, err := version.NewVersion(data.(string))
271+
if err != nil {
272+
return nil, fmt.Errorf("Unable to parse Kafka version: %s", err)
273+
}
274+
275+
for kafkaVersion, constraints := range kafkaVersionConstraints {
276+
if constraints.Check(v) {
277+
return kafkaVersion, nil
278+
}
272279
}
280+
281+
return nil, fmt.Errorf("Unsupported Kafka version: '%s'", data)
273282
}
274283
}
275284

docs/source/kafka.rst

+6-7
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ Additional considerations
7272
Supported Kafka versions and upgrading
7373
--------------------------------------
7474

75-
Fabric uses the `sarama client library <https://github.com/Shopify/sarama>`_ and vendors a version of it that supportes the following Kafka client versions:
75+
Fabric uses the `sarama client library <https://github.com/Shopify/sarama>`_ and vendors a version of it that supports the following Kafka client versions:
7676

77-
* ``Version: 0.9.0.1``
78-
* ``Version: 0.10.0.0``
79-
* ``Version: 0.10.0.1``
80-
* ``Version: 0.10.1.0``
81-
* ``Version: 0.10.2.0``
77+
* ``Version: 0.9.0``
78+
* ``Version: 0.10.0``
79+
* ``Version: 0.10.1``
80+
* ``Version: 0.10.2``
8281

83-
The sample Kafka server image provided by Fabric contains Kafka server version ``0.10.2.0``. Out of the box, Fabric's ordering service nodes default to configuring their embedded Kafka client to match this version. If you are not using the sample Kafka server image provided by Fabric, ensure that you configure a Kafka client version that is compatible with your Kafka server using the ``Kafka.Version`` key in ``orderer.yaml``.
82+
The sample Kafka server image provided by Fabric contains Kafka server version ``0.10.2``. Out of the box, Fabric's ordering service nodes default to configuring their embedded Kafka client to match this version. If you are not using the sample Kafka server image provided by Fabric, ensure that you configure a Kafka client version that is compatible with your Kafka server using the ``Kafka.Version`` key in ``orderer.yaml``.
8483

8584
Debugging
8685
---------

vendor/github.com/Shopify/sarama/CHANGELOG.md

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/README.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/async_producer.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/broker.go

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/client.go

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/consumer.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/crc32_field.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/errors.go

+25-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/mocks/consumer.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Shopify/sarama/utils.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)