Skip to content

Commit

Permalink
change default image (#29)
Browse files Browse the repository at this point in the history
* 0.2.0
  • Loading branch information
rockb1017 authored Jul 1, 2021
1 parent 19ea6a8 commit 8aa7e86
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 77 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci_build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ jobs:
- name: Install Splunk
run: |
# Wait until minikube is ready
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
export JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
echo "wait for minikube ready ..."
sleep 1;
done
kubectl get nodes
# Install Splunk on minikube
kubectl apply -f ci_scripts/k8s-splunk.yml
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.tmp/
.idea/
.deploy/
**/__pycache__/
Binary file removed charts/opentelemetry-collector-0.1.0.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion charts/sck-otel/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: sck-otel
version: 0.1.0
version: 0.2.0
description: Helm chart for Splunk with Open Telemetry Agent
type: application
home: https://github.com/splunk/sck-otel
Expand Down
4 changes: 2 additions & 2 deletions charts/sck-otel/templates/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ receivers:
- type: metadata
id: filename
resource:
service.name: EXPR($$attributes.file_path)
service.name: EXPR($$attributes["file.path"])
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^\/var\/log\/pods\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[^\/]+)\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
parse_from: $$attributes.file_path
parse_from: $$attributes["file.path"]
# Move out attributes to Attributes
- type: metadata
resource:
Expand Down
5 changes: 3 additions & 2 deletions charts/sck-otel/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ batch:
send_batch_max_size: 0

image:
repository: otel/opentelemetry-collector-contrib
repository: rock1017/otelcontribcol
# repository: otel/opentelemetry-collector-contrib
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
tag: "0.30.0"
imagePullSecrets: []

# OpenTelemetry Collector executable
Expand Down
2 changes: 1 addition & 1 deletion ci_scripts/k8s-splunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
runAsGroup: 0
containers:
- name: splunk
image: splunk/splunk:latest
image: splunk/splunk:8.2.0
ports:
- containerPort: 8000
hostPort: 8000
Expand Down
7 changes: 2 additions & 5 deletions ci_scripts/sck_otel_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ containers:
from: namespace
- key: splunk.com/exclude
from: namespace
- key: splunk.com/customField
tag_name: customField
from: namespace
listOfLabels:
- key: app
from: pod
Expand All @@ -79,10 +76,10 @@ customMetadata:
customfield2: customvalue2

image:
repository: otel/opentelemetry-collector-contrib
repository: rock1017/otelcontribcol
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
tag: "0.30.0"
imagePullSecrets: []

# OpenTelemetry Collector executable
Expand Down
7 changes: 4 additions & 3 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
curl -X POST -u admin:helloworld -k https://localhost:8089/servicesNS/nobody/splunk_httpinput/data/inputs/http/http/enable

# Create new HEC token
curl -X POST -u admin:helloworld -k -d "name=splunk_hec_token&token=a6b5e77f-d5f6-415a-bd43-930cecb12959&disabled=0&index=main&indexes=main,circleci_events,ns-anno,pod-anno" https://localhost:8089/servicesNS/nobody/splunk_httpinput/data/inputs/http
curl -X POST -u admin:helloworld -k -d "name=splunk_hec_token&token=a6b5e77f-d5f6-415a-bd43-930cecb12959&disabled=0&index=main&indexes=main,ci_events,ns-anno,pod-anno" https://localhost:8089/servicesNS/nobody/splunk_httpinput/data/inputs/http

# Restart Splunk
curl -k -u admin:helloworld https://localhost:8089/services/server/control/restart -X POST
Expand Down Expand Up @@ -69,11 +69,12 @@
2. Install the dependencies
```
pip install -r requirements.txt
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
```
3. Start the test with the required options configured
```
python -m pytest \
--splunkd-url https://localhost:8089 \
python -m pytest \
--splunkd-url https://localhost:8089 \
--splunk-user admin --splunk-password helloworld \
-p no:warnings -s
```
Expand Down
16 changes: 16 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pytest
import time
import os
from .common import check_events_from_splunk

def pytest_addoption(parser):
parser.addoption("--splunkd-url",
Expand All @@ -35,6 +36,21 @@ def pytest_addoption(parser):
# os.system('docker pull $CI_DATAGEN_IMAGE && kubectl apply -f test_setup.yaml')
# time.sleep(60)

# Print events ingested in splunk for debugging
def pytest_unconfigure(config):
indexes = ["main", "ci_events", "ns-anno", "pod-anno"]
for index in indexes:
search_query = "index=" + index + " | fields *"
events = check_events_from_splunk(start_time="-1h@h",
url=config.getoption("--splunkd-url"),
user=config.getoption("--splunk-user"),
query=["search {0}".format(
search_query)],
password=config.getoption("--splunk-password"))
print("index=" + index + " event count=" + str(len(events)))
for event in events:
print(event)


@pytest.fixture(scope="function")
def setup(request):
Expand Down
16 changes: 8 additions & 8 deletions test/k8s_logging_tests/test_config_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ def test_label_collection(setup, label, index, expected):
assert len(events) >= expected


@pytest.mark.parametrize("container_name,expected", [
("pod-w-index-w-ns-index", 1),
("pod-wo-index-w-ns-index", 1),
("pod-w-index-wo-ns-index", 1),
("pod-wo-index-wo-ns-index", 1),
@pytest.mark.parametrize("index,container_name,expected", [
("pod-anno", "pod-w-index-w-ns-index", 1),
("ns-anno", "pod-wo-index-w-ns-index", 1),
("pod-anno", "pod-w-index-wo-ns-index", 1),
("ci_events", "pod-wo-index-wo-ns-index", 1),
])
def test_annotation_routing(setup, container_name, expected):
def test_annotation_routing(setup, index, container_name, expected):
'''
Test annotation routing feature. it tests different combinations of
namespace annotations and pod annotations.
'''
logger.info("testing test_annotation_routing pod={0} expected={1} event(s)".format(
container_name, expected))
search_query = "index=* container_name::" + container_name
search_query = "index=" + index + " container_name::" + container_name
events = check_events_from_splunk(start_time="-1h@h",
url=setup["splunkd_url"],
user=setup["splunk_user"],
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_custom_metadata_fields(setup, field,value, expected):

@pytest.mark.parametrize("label,index,value,expected", [
("pod-w-index-wo-ns-index", "pod-anno", "pod-value-2", 1),
("pod-wo-index-w-ns-index", "ns-anno", "ns-value", 1),
# ("pod-wo-index-w-ns-index", "ns-anno", "ns-value", 1),
("pod-w-index-w-ns-index", "pod-anno", "pod-value-1", 1)
])
def test_custom_metadata_fields_annotations(setup, label, index, value, expected):
Expand Down
114 changes: 66 additions & 48 deletions test/test_setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ metadata:
splunk.com/index: ns-anno
splunk.com/exclude: "true"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-w-index-w-ns-index
namespace: ns-w-index
spec:
replicas: 1
selector:
matchLabels:
app: pod-w-index-w-ns-index
parallelism: 1
template:
metadata:
labels:
Expand All @@ -39,45 +36,51 @@ spec:
splunk.com/sourcetype: "sourcetype-anno"
splunk.com/customField: pod-value-1
spec:
restartPolicy: Never
containers:
- name: pod-w-index-w-ns-index
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-wo-index-w-ns-index
namespace: ns-w-index
spec:
replicas: 1
selector:
matchLabels:
app: pod-wo-index-w-ns-index
parallelism: 1
template:
metadata:
labels:
app: pod-wo-index-w-ns-index
annotations:
splunk.com/exclude: "false"
spec:
restartPolicy: Never
containers:
- name: pod-wo-index-w-ns-index
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-w-index-wo-ns-index
namespace: ns-wo-index
spec:
replicas: 1
selector:
matchLabels:
app: pod-w-index-wo-ns-index
parallelism: 1
template:
metadata:
labels:
Expand All @@ -86,75 +89,90 @@ spec:
splunk.com/index: "pod-anno"
splunk.com/customField: pod-value-2
spec:
restartPolicy: Never
containers:
- name: pod-w-index-wo-ns-index
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-w-index-w-ns-exclude
namespace: ns-w-exclude
spec:
replicas: 1
selector:
matchLabels:
app: pod-w-index-w-ns-exclude
parallelism: 1
template:
metadata:
labels:
app: pod-w-index-w-ns-exclude
annotations:
splunk.com/index: "pod-anno"
spec:
restartPolicy: Never
containers:
- name: pod-w-index-w-ns-exclude
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-w-exclude-wo-ns-exclude
namespace: ns-w-index
spec:
replicas: 1
selector:
matchLabels:
app: pod-w-index-w-ns-exclude
parallelism: 1
template:
metadata:
labels:
app: pod-w-index-w-ns-exclude
annotations:
splunk.com/exclude: "true"
spec:
restartPolicy: Never
containers:
- name: pod-w-index-w-ns-exclude
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"
---
apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: Job
metadata:
name: pod-wo-index-wo-ns-index
namespace: ns-wo-index
spec:
replicas: 1
selector:
matchLabels:
app: pod-wo-index-wo-ns-index
parallelism: 1
template:
metadata:
labels:
app: pod-wo-index-wo-ns-index
spec:
restartPolicy: Never
containers:
- name: pod-wo-index-wo-ns-index
image: rock1017/log-generator:2.2.4
args:
- "1"
env:
- name: MESSAGE_COUNT
value: "10"
- name: SIZE
value: "256"
- name: FREQ
value: "1"

0 comments on commit 8aa7e86

Please sign in to comment.