Skip to content

Commit 1f58a6e

Browse files
fix: Log file rollover
1 parent da0084b commit 1f58a6e

4 files changed

Lines changed: 111 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ All notable changes to this project will be documented in this file.
3030

3131
- Bump testing-tools to `0.3.0-stackable0.0.0-dev` ([#91]).
3232

33+
### Fixed
34+
35+
- Log file rollover fixed ([#107]).
36+
3337
[#55]: https://github.com/stackabletech/opensearch-operator/pull/55
3438
[#63]: https://github.com/stackabletech/opensearch-operator/pull/63
3539
[#76]: https://github.com/stackabletech/opensearch-operator/pull/76
@@ -38,6 +42,7 @@ All notable changes to this project will be documented in this file.
3842
[#94]: https://github.com/stackabletech/opensearch-operator/pull/94
3943
[#97]: https://github.com/stackabletech/opensearch-operator/pull/97
4044
[#100]: https://github.com/stackabletech/opensearch-operator/pull/100
45+
[#107]: https://github.com/stackabletech/opensearch-operator/pull/107
4146

4247
## [25.11.0] - 2025-11-07
4348

rust/operator-binary/src/controller/build/node_config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
crd::v1alpha1,
1414
framework::{
1515
builder::pod::container::{EnvVarName, EnvVarSet},
16+
product_logging::framework::STACKABLE_LOG_DIR,
1617
role_group_utils,
1718
types::{kubernetes::ServiceName, operator::RoleGroupName},
1819
},
@@ -65,6 +66,13 @@ pub const CONFIG_OPTION_NODE_NAME: &str = "node.name";
6566
/// Type: (comma-separated) list of strings
6667
pub const CONFIG_OPTION_NODE_ROLES: &str = "node.roles";
6768

69+
/// Defines the path for the logs
70+
/// OpenSearch grants the required access rights, see
71+
/// https://github.com/opensearch-project/OpenSearch/blob/3.4.0/server/src/main/java/org/opensearch/bootstrap/Security.java#L369
72+
/// The permissions "write" and "delete" are required for the log file rollover.
73+
/// Type: string
74+
pub const CONFIG_OPTION_PATH_LOGS: &str = "path.logs";
75+
6876
/// Specifies a list of distinguished names (DNs) that denote the other nodes in the cluster.
6977
/// Type: (comma-separated) list of strings
7078
pub const CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN: &str = "plugins.security.nodes_dn";
@@ -203,6 +211,13 @@ impl NodeConfig {
203211
CONFIG_OPTION_NODE_ATTR_ROLE_GROUP.to_owned(),
204212
json!(self.role_group_name),
205213
);
214+
config.insert(
215+
CONFIG_OPTION_PATH_LOGS.to_owned(),
216+
json!(format!(
217+
"{STACKABLE_LOG_DIR}/{container}",
218+
container = v1alpha1::Container::OpenSearch.to_container_name()
219+
)),
220+
);
206221

207222
config
208223
}

tests/templates/kuttl/logging/20-install-opensearch.yaml.j2

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ data:
1313
appender.FILE.layout.type = OpenSearchJsonLayout
1414
appender.FILE.layout.type_name = server
1515
---
16+
# Expose the API of the Vector agent
17+
apiVersion: v1
18+
kind: ConfigMap
19+
metadata:
20+
name: vector-api-config
21+
data:
22+
vector-api-config.yaml: |
23+
api:
24+
address: 0.0.0.0:8686
25+
enabled: true
26+
---
27+
# Expose the API of the Vector agent of the pod opensearch-nodes-automatic-0
28+
apiVersion: v1
29+
kind: Service
30+
metadata:
31+
name: opensearch-nodes-automatic-vector
32+
spec:
33+
ports:
34+
- name: vector
35+
port: 8686
36+
protocol: TCP
37+
selector:
38+
app.kubernetes.io/component: nodes
39+
app.kubernetes.io/instance: opensearch
40+
app.kubernetes.io/name: opensearch
41+
app.kubernetes.io/role-group: automatic
42+
type: ClusterIP
43+
---
1644
apiVersion: opensearch.stackable.tech/v1alpha1
1745
kind: OpenSearchCluster
1846
metadata:
@@ -37,10 +65,10 @@ spec:
3765
console:
3866
level: INFO
3967
file:
40-
level: INFO
68+
level: TRACE
4169
loggers:
4270
ROOT:
43-
level: INFO
71+
level: TRACE
4472
vector:
4573
console:
4674
level: INFO
@@ -78,10 +106,26 @@ spec:
78106
- name: security-config
79107
mountPath: /stackable/opensearch/config/opensearch-security
80108
readOnly: true
109+
- name: vector
110+
env:
111+
- name: VECTOR_CONFIG_YAML
112+
value: /stackable/config/vector.yaml,/stackable/config/vector-api-config.yaml
113+
ports:
114+
- name: vector
115+
containerPort: 8686
116+
protocol: TCP
117+
volumeMounts:
118+
- name: vector-api-config
119+
mountPath: /stackable/config/vector-api-config.yaml
120+
readOnly: true
121+
subPath: vector-api-config.yaml
81122
volumes:
82123
- name: security-config
83124
secret:
84125
secretName: opensearch-security-config
126+
- name: vector-api-config
127+
configMap:
128+
name: vector-api-config
85129
---
86130
apiVersion: v1
87131
kind: Secret

tests/templates/kuttl/logging/30-test-opensearch.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ spec:
3737
securityContext:
3838
fsGroup: 1000
3939
restartPolicy: OnFailure
40+
backoffLimit: 10
4041
---
4142
apiVersion: v1
4243
kind: ConfigMap
@@ -88,6 +89,50 @@ data:
8889
f'No events were sent in "{componentId}".'
8990
9091
92+
def check_log_file_rollover():
93+
response = requests.post(
94+
'http://opensearch-nodes-automatic-vector:8686/graphql',
95+
json={
96+
'query': """
97+
{
98+
sources {
99+
nodes {
100+
componentId
101+
metrics {
102+
receivedBytesTotal {
103+
receivedBytesTotal
104+
}
105+
}
106+
}
107+
}
108+
}
109+
"""
110+
}
111+
)
112+
113+
assert response.status_code == 200, \
114+
'Cannot access the API of the vector agent.'
115+
116+
result = response.json()
117+
118+
sources = result['data']['sources']['nodes']
119+
for source in sources:
120+
receivedBytes = source['metrics']['receivedBytesTotal']
121+
componentId = source['componentId']
122+
123+
if componentId == 'files_opensearch_server':
124+
assert receivedBytes is not None
125+
receivedBytes = receivedBytes['receivedBytesTotal']
126+
MAX_LOG_FILE_SIZE = 5_500_000
127+
expectedBytes = 2 * MAX_LOG_FILE_SIZE
128+
assert receivedBytes >= expectedBytes, \
129+
'Log file rollover did not yet happen twice ' \
130+
f'({receivedBytes:,.0f} Bytes of {expectedBytes:,d} Bytes received). ' \
131+
'The first rollover requires write permission to rename the log file, ' \
132+
'the second rollover additionally requires delete permission to remove the old log file.'
133+
134+
91135
if __name__ == '__main__':
92136
check_sent_events()
137+
check_log_file_rollover()
93138
print('Test successful!')

0 commit comments

Comments
 (0)