Skip to content

Commit 3e5a167

Browse files
authored
Make API address and Shard ID required in Cloud Foundry settings (#21759)
Having an auto-generated Shard ID leads to duplicated data when trying to scale, increasing the problems of loaded systems. Forcing to set a shard ID makes the user more conscious of the implications of this setting. API address should be always set in a real deployment.
1 parent 1685f97 commit 3e5a167

16 files changed

Lines changed: 55 additions & 34 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
2525
- Allow embedding of CAs, Certificate of private keys for anything that support TLS in ouputs and inputs https://github.com/elastic/beats/pull/21179
2626
- Update to Golang 1.12.1. {pull}11330[11330]
2727
- Disable Alibaba Cloud and Tencent Cloud metadata providers by default. {pull}13812[12812]
28+
- API address is a required setting in `add_cloudfoundry_metadata`. {pull}21759[21759]
2829

2930
*Auditbeat*
3031

@@ -78,6 +79,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
7879
- Removed experimental modules `citrix`, `kaspersky`, `rapid7` and `tenable`. {pull}20706[20706]
7980
- Add support for GMT timezone offsets in `decode_cef`. {pull}20993[20993]
8081
- Fix parsing of Elasticsearch node name by `elasticsearch/slowlog` fileset. {pull}14547[14547]
82+
- API address and shard ID are required settings in the Cloud Foundry input. {pull}21759[21759]
8183

8284
*Heartbeat*
8385

@@ -95,6 +97,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
9597
- Fix ECS compliance of user.id field in system/users metricset {pull}19019[19019]
9698
- Rename googlecloud stackdriver metricset to metrics. {pull}19718[19718]
9799
- Remove "invalid zero" metrics on Windows and Darwin, don't report linux-only memory and diskio metrics when running under agent. {pull}21457[21457]
100+
- API address and shard ID are required settings in the Cloud Foundry module. {pull}21759[21759]
98101

99102
*Packetbeat*
100103

deploy/cloudfoundry/filebeat/filebeat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ filebeat.inputs:
1111
#doppler_address: ${DOPPLER_ADDRESS}
1212
#uaa_address: ${UAA_ADDRESS}
1313
#rlp_address: ${RLP_ADDRESS}
14-
#shard_id: ${SHARD_ID}
14+
shard_id: ${SHARD_ID}
1515
#version: v1
1616

1717

deploy/cloudfoundry/metricbeat/metricbeat.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ metricbeat.modules:
1111
#doppler_address: ${DOPPLER_ADDRESS}
1212
#uaa_address: ${UAA_ADDRESS}
1313
#rlp_address: ${RLP_ADDRESS}
14-
#shard_id: ${SHARD_ID}
14+
shard_id: ${SHARD_ID}
15+
#version: v1
1516

1617

1718
#================================ Outputs =====================================

filebeat/docs/running-on-cloudfoundry.asciidoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,3 @@ filebeat started 1/1 512M 1G
7171

7272
Log events should start flowing to Elasticsearch. The events are annotated with
7373
metadata added by the <<add-cloudfoundry-metadata>> processor.
74-
75-
76-
[WARNING]
77-
=======================================
78-
*Set shard_id to scale:* By default {beatname_uc} will generate a random `shard_id` when it starts. In the case that
79-
{beatname_uc} needs to be scaled passed 1 instance, be sure to set a static `shard_id`. Not setting a static `shard_id`
80-
will result in duplicate events being pushed to Elasticsearch.
81-
=======================================

metricbeat/docs/modules/cloudfoundry.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Client Secret to authenticate with Cloud Foundry. Default: "".
117117
=== `shard_id`
118118

119119
Shard ID for connection to the RLP Gateway. Use the same ID across multiple {beatname_lc} to shard the load of events
120-
from the RLP Gateway. Default: "(generated UUID)".
120+
from the RLP Gateway.
121121

122122
[float]
123123
==== `version`
@@ -152,6 +152,7 @@ metricbeat.modules:
152152
rlp_address: '${CLOUDFOUNDRY_RLP_ADDRESS:""}'
153153
client_id: '${CLOUDFOUNDRY_CLIENT_ID:""}'
154154
client_secret: '${CLOUDFOUNDRY_CLIENT_SECRET:""}'
155+
shard_id: metricbeat
155156
version: v1
156157
----
157158

metricbeat/docs/running-on-cloudfoundry.asciidoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,3 @@ metricbeat started 1/1 512M 1G
7171

7272
Metrics should start flowing to Elasticsearch. The events are annotated with
7373
metadata added by the <<add-cloudfoundry-metadata>> processor.
74-
75-
76-
[WARNING]
77-
=======================================
78-
*Set shard_id to scale:* By default {beatname_uc} will generate a random `shard_id` when it starts. In the case that
79-
{beatname_uc} needs to be scaled passed 1 instance, be sure to set a static `shard_id`. Not setting a static `shard_id`
80-
will result in duplicate events being pushed to Elasticsearch.
81-
=======================================

x-pack/filebeat/docs/inputs/input-cloudfoundry.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Example configurations:
2323
api_address: https://api.dev.cfdev.sh
2424
client_id: uaa-filebeat
2525
client_secret: verysecret
26+
shard_id: filebeat
2627
ssl:
2728
verification_mode: none
2829
----
@@ -34,6 +35,7 @@ Example configurations:
3435
api_address: https://api.dev.cfdev.sh
3536
client_id: uaa-filebeat
3637
client_secret: verysecret
38+
shard_id: filebeat
3739
ssl.certificate_authorities: ["/etc/pki/cf/ca.pem"]
3840
ssl.certificate: "/etc/pki/cf/cert.pem"
3941
ssl.key: "/etc/pki/cf/cert.key"

x-pack/libbeat/common/cloudfoundry/config.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/gofrs/uuid"
14-
1513
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
1614
)
1715

@@ -32,14 +30,14 @@ type Config struct {
3230
TLS *tlscommon.Config `config:"ssl"`
3331

3432
// Override URLs returned from the CF client
35-
APIAddress string `config:"api_address"`
33+
APIAddress string `config:"api_address" validate:"required"`
3634
DopplerAddress string `config:"doppler_address"`
3735
UaaAddress string `config:"uaa_address"`
3836
RlpAddress string `config:"rlp_address"`
3937

4038
// ShardID when retrieving events from loggregator, sharing this ID across
4139
// multiple filebeats will shard the load of receiving and sending events.
42-
ShardID string `config:"shard_id"`
40+
ShardID string `config:"shard_id" validate:"required"`
4341

4442
// Maximum amount of time to cache application objects from CF client.
4543
CacheDuration time.Duration `config:"cache_duration"`
@@ -50,13 +48,6 @@ type Config struct {
5048

5149
// InitDefaults initialize the defaults for the configuration.
5250
func (c *Config) InitDefaults() {
53-
// If not provided by the user; subscription ID should be a unique string to avoid clustering by default.
54-
// Default to using a UUID4 string.
55-
uuid, err := uuid.NewV4()
56-
if err != nil {
57-
panic(err)
58-
}
59-
c.ShardID = uuid.String()
6051
c.CacheDuration = 120 * time.Second
6152
c.CacheRetryDelay = 20 * time.Second
6253
c.Version = ConsumerVersionV1

x-pack/libbeat/common/cloudfoundry/config_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,48 @@ func TestValidation(t *testing.T) {
2222

2323
var noId Config
2424
assert.Error(t, ucfg.MustNewFrom(common.MapStr{
25+
"api_address": "https://api.dev.cfdev.sh",
2526
"client_secret": "client_secret",
27+
"shard_id": "beats-test-1",
2628
}).Unpack(&noId))
2729

2830
var noSecret Config
2931
assert.Error(t, ucfg.MustNewFrom(common.MapStr{
30-
"client_id": "client_id",
32+
"api_address": "https://api.dev.cfdev.sh",
33+
"client_id": "client_id",
34+
"shard_id": "beats-test-1",
3135
}).Unpack(&noSecret))
3236

37+
var noAPI Config
38+
assert.Error(t, ucfg.MustNewFrom(common.MapStr{
39+
"client_id": "client_id",
40+
"client_secret": "client_secret",
41+
"shard_id": "beats-test-1",
42+
}).Unpack(&noAPI))
43+
44+
var noShardID Config
45+
assert.Error(t, ucfg.MustNewFrom(common.MapStr{
46+
"api_address": "https://api.dev.cfdev.sh",
47+
"client_id": "client_id",
48+
"client_secret": "client_secret",
49+
}).Unpack(&noShardID))
50+
3351
var valid Config
3452
assert.NoError(t, ucfg.MustNewFrom(common.MapStr{
53+
"api_address": "https://api.dev.cfdev.sh",
3554
"client_id": "client_id",
3655
"client_secret": "client_secret",
56+
"shard_id": "beats-test-1",
3757
}).Unpack(&valid))
3858
}
3959

4060
func TestInitDefaults(t *testing.T) {
4161
var cfCfg Config
4262
assert.NoError(t, ucfg.MustNewFrom(common.MapStr{
63+
"api_address": "https://api.dev.cfdev.sh",
4364
"client_id": "client_id",
4465
"client_secret": "client_secret",
66+
"shard_id": "beats-test-1",
4567
}).Unpack(&cfCfg))
46-
assert.Len(t, cfCfg.ShardID, 36)
68+
assert.Equal(t, ConsumerVersionV1, cfCfg.Version)
4769
}

x-pack/libbeat/common/cloudfoundry/test/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@ package test
77
import (
88
"os"
99
"testing"
10+
11+
"github.com/gofrs/uuid"
1012
)
1113

1214
func GetConfigFromEnv(t *testing.T) map[string]interface{} {
1315
t.Helper()
1416

17+
shardID, err := uuid.NewV4()
18+
if err != nil {
19+
t.Fatalf("Unable to create a random shard ID: %v", err)
20+
}
21+
1522
config := map[string]interface{}{
1623
"api_address": lookupEnv(t, "CLOUDFOUNDRY_API_ADDRESS"),
1724
"client_id": lookupEnv(t, "CLOUDFOUNDRY_CLIENT_ID"),
1825
"client_secret": lookupEnv(t, "CLOUDFOUNDRY_CLIENT_SECRET"),
26+
"shard_id": shardID.String(),
1927

2028
"ssl.verification_mode": "none",
2129
}
2230

2331
optionalConfig(config, "uaa_address", "CLOUDFOUNDRY_UAA_ADDRESS")
2432
optionalConfig(config, "rlp_address", "CLOUDFOUNDRY_RLP_ADDRESS")
2533
optionalConfig(config, "doppler_address", "CLOUDFOUNDRY_DOPPLER_ADDRESS")
26-
optionalConfig(config, "shard_id", "CLOUDFOUNDRY_SHARD_ID")
2734

2835
if t.Failed() {
2936
t.FailNow()

0 commit comments

Comments
 (0)