Skip to content

Commit a9761a0

Browse files
authored
Merge pull request #249 from splunk/dev/test-upgrade-INGEST-17735
added test update connectors after upgrade
2 parents db6b4d2 + 33e0a95 commit a9761a0

File tree

3 files changed

+135
-47
lines changed

3 files changed

+135
-47
lines changed

.circleci/config.yml

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
version: 2
1+
version: 2.1
2+
3+
workflows:
4+
version: 2.1
5+
test:
6+
jobs:
7+
- build_test:
8+
filters:
9+
branches:
10+
ignore:
11+
- /^release\/.*/
12+
- master
13+
214
jobs:
315
build_test:
416
resource_class: large
@@ -47,26 +59,39 @@ jobs:
4759
- run:
4860
name: Create file for checksum
4961
command: echo $CI_SPLUNK_VERSION > /tmp/splunk_version.txt
62+
- install_splunk
63+
- install_kafka
64+
- test_kafka_connect_upgrade
65+
- run_functional_tests
66+
67+
commands:
68+
install_splunk:
69+
description: "Install Splunk"
70+
steps:
5071
- run:
5172
name: Install Splunk
5273
command: |
5374
cd /tmp && wget -O $CI_SPLUNK_FILENAME 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version='$CI_SPLUNK_VERSION'&product=splunk&filename='$CI_SPLUNK_FILENAME'&wget=true'
5475
sudo dpkg -i $CI_SPLUNK_FILENAME
5576
# Set user seed
5677
hashed_pwd=$(sudo /opt/splunk/bin/splunk hash-passwd $CI_SPLUNK_PASSWORD)
57-
sudo tee /opt/splunk/etc/system/local/user-seed.conf > /dev/null << EOF
78+
sudo tee /opt/splunk/etc/system/local/user-seed.conf > /dev/null \<< EOF
5879
[user_info]
5980
USERNAME = $CI_SPLUNK_USERNAME
6081
HASHED_PASSWORD = $hashed_pwd
6182
EOF
6283
# Add delete capability to admin role
63-
sudo tee -a /opt/splunk/etc/system/local/authorize.conf > /dev/null << EOF
84+
sudo tee -a /opt/splunk/etc/system/local/authorize.conf > /dev/null \<< EOF
6485
[role_admin]
6586
delete_by_keyword = enabled
6687
EOF
67-
# start Splunk
88+
- run:
89+
name: Start Splunk
90+
command: |
6891
sudo /opt/splunk/bin/splunk start --accept-license --answer-yes --no-prompt
69-
# Enable HEC services
92+
- run:
93+
name: Enable HEC services
94+
command: |
7095
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/nobody/splunk_httpinput/data/inputs/http/http/enable
7196
# Create new HEC token
7297
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k -d "name=splunk_hec_token&token=$CI_SPLUNK_HEC_TOKEN" https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/nobody/splunk_httpinput/data/inputs/http
@@ -78,18 +103,24 @@ jobs:
78103
sudo /opt/splunk/bin/splunk http-event-collector enable -name splunk_hec_token_ack -uri https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT -auth $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD
79104
# Disable SSL for HEC new-token
80105
#sudo /opt/splunk/bin/splunk http-event-collector update -uri https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT -enable-ssl 0 -auth $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD
81-
# Setup Indexes
106+
- run:
107+
name: Setup Indexes
108+
command: |
82109
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k -d "name=$CI_INDEX_EVENTS&datatype=event" https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/-/search/data/indexes
83110
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k -d "name=$CI_KAFKA_HEADER_INDEX&datatype=event" https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/-/search/data/indexes
84111
sudo /opt/splunk/bin/splunk restart --accept-license --answer-yes --no-prompt
112+
113+
install_kafka:
114+
description: "Install Kafka"
115+
steps:
85116
- run:
86117
name: Install Kafka
87118
command: |
88119
cd /tmp && wget http://www-us.apache.org/dist/kafka/$CI_KAFKA_VERSION/$CI_KAFKA_FILENAME
89120
sudo tar xzf $CI_KAFKA_FILENAME
90121
rm $CI_KAFKA_FILENAME
91122
sudo mv kafka_* /usr/local/kafka
92-
sudo tee /etc/systemd/system/zookeeper.service > /dev/null << EOF
123+
sudo tee /etc/systemd/system/zookeeper.service > /dev/null \<< EOF
93124
[Unit]
94125
Description=Apache Zookeeper server
95126
Documentation=http://zookeeper.apache.org
@@ -104,7 +135,7 @@ jobs:
104135
WantedBy=multi-user.target
105136
EOF
106137
107-
sudo tee /etc/systemd/system/kafka.service > /dev/null << EOF
138+
sudo tee /etc/systemd/system/kafka.service > /dev/null \<< EOF
108139
[Unit]
109140
Description=Apache Kafka Server
110141
Documentation=http://kafka.apache.org/documentation.html
@@ -117,49 +148,46 @@ jobs:
117148
[Install]
118149
WantedBy=multi-user.target
119150
EOF
151+
- run:
152+
name: Start Kafka Server
153+
command: |
120154
sudo systemctl daemon-reload
121155
sudo systemctl start zookeeper
122156
sudo systemctl start kafka
157+
test_kafka_connect_upgrade:
158+
description: "Test kafka connect upgrade"
159+
steps:
123160
- run:
124-
name: Setup kafka connect
161+
name: Test kafka connect upgrade
125162
command: |
163+
echo "Download kafka connect "$CI_OLD_CONNECTOR_VERSION
126164
sudo mkdir -p /usr/local/share/kafka/plugins/
127165
wget https://github.com/splunk/kafka-connect-splunk/releases/download/$CI_OLD_CONNECTOR_VERSION/splunk-kafka-connect-$CI_OLD_CONNECTOR_VERSION.jar
128166
sudo cp splunk-kafka-connect-$CI_OLD_CONNECTOR_VERSION.jar /usr/local/share/kafka/plugins/
129167
sed -i 's/plugin\.path\=connectors\//plugin\.path\=\/usr\/local\/share\/kafka\/plugins\//' /home/circleci/repo/config/connect-distributed-quickstart.properties
130168
sed -i 's/key\.converter\=org\.apache\.kafka\.connect\.storage\.StringConverter/key\.converter\=org\.apache\.kafka\.connect\.json\.JsonConverter/' /home/circleci/repo/config/connect-distributed-quickstart.properties
131169
sed -i 's/value\.converter\=org\.apache\.kafka\.connect\.storage\.StringConverter/value\.converter\=org\.apache\.kafka\.connect\.json\.JsonConverter/' /home/circleci/repo/config/connect-distributed-quickstart.properties
132-
- run:
133-
name: Test kafka connect upgrade
134-
command: |
135170
pyenv global 3.6.5
136171
pip install --upgrade pip
137172
pip install -r test/requirements.txt
138173
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
139174
echo "Test kafka connect upgrade ..."
140175
python test/lib/connector_upgrade.py
176+
177+
run_functional_tests:
178+
description: "Run functional tests on current kafka connect version"
179+
steps:
141180
- run:
142-
name: Start kafka connect
181+
name: Install kafka connect
143182
command: |
183+
sudo rm -f /usr/local/share/kafka/plugins/splunk-kafka-connect*.jar
184+
sudo cp /home/circleci/repo/target/splunk-kafka-connect*.jar /usr/local/share/kafka/plugins/
185+
test -f /usr/local/share/kafka/plugins/splunk-kafka-connect*.jar && echo /usr/local/share/kafka/plugins/splunk-kafka-connect*.jar
144186
sudo /usr/local/kafka/bin/connect-distributed.sh /home/circleci/repo/config/connect-distributed-quickstart.properties
145187
background: true
146188
- run:
147189
name: Run Functional tests
148190
command: |
149191
sleep 5
150-
sudo apt-get install jq
151-
curl localhost:8083/connector-plugins | jq
152192
echo "Running functional tests....."
153193
python -m pytest -p no:warnings -s
154-
155-
workflows:
156-
version: 2
157-
test:
158-
jobs:
159-
- build_test:
160-
filters:
161-
branches:
162-
ignore:
163-
- /^release\/.*/
164-
- master
165-

test/lib/connector_upgrade.py

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
config = yaml.load(yaml_file)
2323
now = datetime.now()
2424
_time_stamp = str(datetime.timestamp(now))
25+
_topic = 'kafka_connect_upgrade'
26+
_connector = 'kafka_connect'
27+
_connector_ack = 'kafka_connect_ack'
2528

2629

2730
def start_old_connector():
@@ -41,47 +44,53 @@ def start_old_connector():
4144

4245
def generate_kafka_events(num):
4346
# Generate message data
44-
topics = ["kafka_data_gen"]
47+
topics = [_topic]
4548
connector_content = {
46-
"name": "kafka_connect",
49+
"name": _connector,
4750
"config": {
4851
"connector.class": "com.splunk.kafka.connect.SplunkSinkConnector",
4952
"tasks.max": "1",
5053
"splunk.indexes": config["splunk_index"],
51-
"topics": "kafka_data_gen",
54+
"topics": _topic,
5255
"splunk.hec.ack.enabled": "false",
5356
"splunk.hec.uri": config["splunk_hec_url"],
5457
"splunk.hec.ssl.validate.certs": "false",
55-
"splunk.hec.token": config["splunk_token"]
58+
"splunk.hec.token": config["splunk_token"],
59+
"splunk.sources": _connector
5660
}
5761
}
5862
create_kafka_connector(config, connector_content)
5963
connector_content_ack = {
60-
"name": "kafka_connect_ack",
64+
"name": _connector_ack,
6165
"config": {
6266
"connector.class": "com.splunk.kafka.connect.SplunkSinkConnector",
6367
"tasks.max": "1",
6468
"splunk.indexes": config["splunk_index"],
65-
"topics": "kafka_data_gen",
69+
"topics": _topic,
6670
"splunk.hec.ack.enabled": "true",
6771
"splunk.hec.uri": config["splunk_hec_url"],
6872
"splunk.hec.ssl.validate.certs": "false",
69-
"splunk.hec.token": config["splunk_token_ack"]
73+
"splunk.hec.token": config["splunk_token_ack"],
74+
"splunk.sources": _connector_ack
7075
}
7176
}
7277
create_kafka_connector(config, connector_content_ack)
73-
create_kafka_topics(config, topics)
78+
client = KafkaAdminClient(bootstrap_servers=config["kafka_broker_url"], client_id='test')
79+
broker_topics = client.list_topics()
80+
logger.info(broker_topics)
81+
if _topic not in broker_topics:
82+
create_kafka_topics(config, topics)
7483
producer = KafkaProducer(bootstrap_servers=config["kafka_broker_url"],
7584
value_serializer=lambda v: json.dumps(v).encode('utf-8'))
7685

7786
for _ in range(num):
7887
msg = {"timestamp": _time_stamp}
79-
producer.send("kafka_data_gen", msg)
88+
producer.send(_topic, msg)
8089
time.sleep(0.05)
8190
producer.flush()
8291

8392

84-
def upgrade_connector():
93+
def upgrade_connector_plugin():
8594
cmds = ["sudo kill $(sudo lsof -t -i:8083) && sleep 2",
8695
"sudo rm {}/{} && sleep 2".format(config["connector_path"], config["old_connector_name"]),
8796
"sudo cp {0}/splunk-kafka-connect*.jar {1} && sleep 2".format(config["connector_build_target"],
@@ -96,10 +105,50 @@ def upgrade_connector():
96105
stderr=subprocess.STDOUT)
97106
output, error = proc.communicate()
98107
logger.info(output)
108+
time.sleep(2)
109+
update_kafka_connectors()
99110
except OSError as e:
100111
logger.error(e)
101112

102113

114+
def update_kafka_connectors():
115+
logger.info("Update kafka connectors ...")
116+
connector_content = {
117+
"name": _connector,
118+
"config": {
119+
"connector.class": "com.splunk.kafka.connect.SplunkSinkConnector",
120+
"tasks.max": "1",
121+
"splunk.indexes": config["splunk_index"],
122+
"topics": _topic,
123+
"splunk.hec.ack.enabled": "false",
124+
"splunk.hec.uri": config["splunk_hec_url"],
125+
"splunk.hec.ssl.validate.certs": "false",
126+
"splunk.hec.token": config["splunk_token"],
127+
"splunk.sources": _connector,
128+
"splunk.hec.json.event.formatted": "true",
129+
"splunk.hec.raw": True
130+
}
131+
}
132+
create_kafka_connector(config, connector_content)
133+
connector_content_ack = {
134+
"name": _connector_ack,
135+
"config": {
136+
"connector.class": "com.splunk.kafka.connect.SplunkSinkConnector",
137+
"tasks.max": "1",
138+
"splunk.indexes": config["splunk_index"],
139+
"topics": _topic,
140+
"splunk.hec.ack.enabled": "true",
141+
"splunk.hec.uri": config["splunk_hec_url"],
142+
"splunk.hec.ssl.validate.certs": "false",
143+
"splunk.hec.token": config["splunk_token_ack"],
144+
"splunk.sources": _connector_ack,
145+
"splunk.hec.json.event.formatted": "true",
146+
"splunk.hec.raw": True
147+
}
148+
}
149+
create_kafka_connector(config, connector_content_ack)
150+
151+
103152
if __name__ == '__main__':
104153
logger.info("Start old Kafka connector ...")
105154
thread_old_connect = threading.Thread(target=start_old_connector, daemon=True)
@@ -110,15 +159,26 @@ def upgrade_connector():
110159
thread_gen.start()
111160
time.sleep(50)
112161
logger.info("Upgrade Kafka connector ...")
113-
thread_upgrade = threading.Thread(target=upgrade_connector, daemon=True)
162+
thread_upgrade = threading.Thread(target=upgrade_connector_plugin, daemon=True)
114163
thread_upgrade.start()
115164
time.sleep(100)
116-
search_query = "index={0} | search timestamp=\"{1}\"".format(config['splunk_index'], _time_stamp)
117-
logger.info(search_query)
118-
events = check_events_from_splunk(start_time="-15m@m",
165+
search_query_1 = "index={0} | search timestamp=\"{1}\" source::{2}".format(config['splunk_index'], _time_stamp,
166+
_connector)
167+
logger.info(search_query_1)
168+
events_1 = check_events_from_splunk(start_time="-15m@m",
119169
url=config["splunkd_url"],
120170
user=config["splunk_user"],
121-
query=["search {}".format(search_query)],
171+
query=["search {}".format(search_query_1)],
122172
password=config["splunk_password"])
123-
logger.info("Splunk received %s events in the last 15m", len(events))
124-
assert len(events) == 4000
173+
logger.info("Splunk received %s events in the last 15m", len(events_1))
174+
assert len(events_1) == 2000
175+
search_query_2 = "index={0} | search timestamp=\"{1}\" source::{2}".format(config['splunk_index'], _time_stamp,
176+
_connector_ack)
177+
logger.info(search_query_2)
178+
events_2 = check_events_from_splunk(start_time="-15m@m",
179+
url=config["splunkd_url"],
180+
user=config["splunk_user"],
181+
query=["search {}".format(search_query_2)],
182+
password=config["splunk_password"])
183+
logger.info("Splunk received %s events in the last 15m", len(events_2))
184+
assert len(events_2) == 2000

test/testcases/test_configurations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def test_header_support_false_event_data(self, setup, test_scenario, test_input,
141141
def test_header_support_true_event_data(self, setup, test_scenario, test_input, expected):
142142
logger.info("testing {0} input={1} expected={2} event(s)".format(test_scenario, test_input, expected))
143143

144-
search_query = "index={0} | search timestamp=\"{1}\" {2}".format(setup['kafka_header_index'],
145-
setup["timestamp"],
146-
test_input)
144+
search_query = "index={0} | search \"{1}\" {2}".format(setup['kafka_header_index'],
145+
setup["timestamp"],
146+
test_input)
147147
logger.info(search_query)
148148
events = check_events_from_splunk(start_time="-15m@m",
149149
url=setup["splunkd_url"],

0 commit comments

Comments
 (0)