Files
openobserve/tests/api-testing/tests/test_try_castqueries.py
T
+2 0d9f47966b feat: Organization revamp (#5579)
Fixes #5131 
Addresses #5408 

### Revamp
- Created a new table to store organizations in the `organizations`
table. Earlier, we never stored organizations in any table, rather we
used to store the organizations in the meta table as part of the `user`
json.
- The users and organization membership relations are now moved to its
own separate tables - `users` and `org_users`.

### New changes

**API changes** -
- `/organizations` - `POST` api to create an org and save it in the meta
table. In non-enterprise version, currently only the root user can
create the org. For enterprise version with rbac enabled, anyone with
`CREATE` access for organizations can create the organization and
becomes an admin. Root user can always create an organization.
- `/{org_id}/rename` - `PUT` api to rename the existing org. Only root
user and the admins of the org can access this API.

The payload for following APIs are changed -
- `POST api/{org_id}/roles` - `{"name":"new_role"}` is changed to
`{"role":"new_role"}
- `POST api/{org_id}/users/{user}` -
`{"role":"viewer","custom_role":["role_name"]}` is the new payload where
`custom_role` is optional and is array of custom roles (only works in
enterprise with rbac enabled) which will be assigned to the user. The
value of `role` can be standard role or as well as any custom role (when
it is custom role, the standard role assigned to the user is decided
based on the enterprise env variable - `O2_DEX_DEFAULT_ROLE`).
- `POST api/{org_id}/users`- the payload -
```
{"email":"user@user.com","role":"viewer","custom_role":["create_org_permission"],"password":"12345678", "first_name": "", "last_name":""}
```

- `PUT api//{org_id}/users/{email_id}` the payload -
```
{"first_name":"Hello","last_name":"j","role":"viewer","isExternal":false,"change_password":false,"password":"","custom_role":["create_org_permission"]}
```


A new ENV variable is introduced - `ZO_CREATE_ORG_THROUGH_INGESTION`
(default `false`) which if true, an org will automatically created when
ingesting data to a new org. If false, user can not create org by
ingesting data to new org, they need to first call the `POST
/organizations` API.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

**New Features**
- Added a `cloud` feature for enhanced organizational management
capabilities.
- Introduced new methods for managing organizational users and
asynchronous message processing.
- Enhanced user invitation and membership features, including improved
role handling.
- Implemented configurable ingestion URL support across various
components.
- Added new functionality for user management and organization handling
in the super cluster architecture.

**Improvements**
- Refined user authentication and authorization processes, including
error handling.
- Updated database schema to support multi-organization architecture.
- Enhanced pagination settings and UI components for better user
experience.
- Improved handling of organization names and user roles in
notifications and alerts.
- Streamlined service account token management with visibility
enhancements.
- Enhanced the `AddUpdateOrganization` component with improved user
input handling and validation.
- Updated the `AppOrganizations` component to dynamically load the
appropriate organization management interface.
- Improved the `ServiceAccountsList` component with updated pagination
options and token handling logic.

**Bug Fixes**
- Resolved issues with user role assignments and organization management
inconsistencies.
- Corrected routing and navigation logic for login and logout processes.
- Addressed various error handling scenarios in user and organization
processes.
- Fixed issues with the visibility of service account options in the
`EditGroup` and `EditRole` components based on the cloud configuration.

**Breaking Changes**
- Significant restructuring of user and organization data models.
- Changes to authentication workflows and configuration handling.
- Removal of certain components related to user and organization
management.
- Updated the logic for determining the ingestion URL across various
components.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
Co-authored-by: Bhargav <BJP232004@GMAIL.COM>
Co-authored-by: Taiming Liu <liutaiming3@gmail.com>
Co-authored-by: hengfei yang <hengfei.yang@gmail.com>
Co-authored-by: harshiv-7 <harshiv@openobserve.ai>
Co-authored-by: Huaijin <haohuaijin@gmail.com>
Co-authored-by: Zhao.wei <weizhao029@gmail.com>
Co-authored-by: ShyamOOAI <shyam@openobserve.ai>
Co-authored-by: oasisk <ashish.j.kolhe@gmail.com>
Co-authored-by: sai nikhil kethe <nikhil@openobserve.ai>
Co-authored-by: Yashodhan Joshi <yashodhan@openobserve.ai>
Co-authored-by: Yashodhan Joshi <yjdoc2@gmail.com>
2025-05-25 21:53:55 -07:00

86 lines
2.5 KiB
Python

import pytest
from datetime import datetime, timezone, timedelta
# Define test data with different queries and expected response details for cast abd try_cast
test_data = [
(
"logs query",
"SELECT kubernetes_namespace_name from stream_pytest_data LIMIT 1",
1,
),
(
"logs cast text query",
"SELECT cast(kubernetes_namespace_name as Text) as kubernetes_namespace_name from stream_pytest_data LIMIT 1",
1,
),
(
"logs try_cast text query",
"SELECT try_cast(kubernetes_namespace_name as Text) as kubernetes_namespace_name from stream_pytest_data LIMIT 1",
1,
),
(
"logs cast VARCHAR query",
"SELECT cast(kubernetes_namespace_name as VARCHAR) as kubernetes_namespace_name from stream_pytest_data LIMIT 1",
1,
),
(
"logs try_cast VARCHAR query",
"SELECT try_cast(kubernetes_namespace_name as VARCHAR) as kubernetes_namespace_name from stream_pytest_data LIMIT 1",
1,
),
(
"logs integer comparison query",
'SELECT * FROM "stream_pytest_data" WHERE k8s_container_restart_count = 1',
1,
),
(
"logs integer cast comparison query",
'SELECT * FROM "stream_pytest_data" WHERE cast(k8s_container_restart_count as INT) = 1',
1,
),
(
"logs integer try_cast comparison query",
'SELECT * FROM "stream_pytest_data" WHERE try_cast(k8s_container_restart_count as INT) = 1',
1,
),
]
@pytest.mark.parametrize("test_name, sql_query, expected_size", test_data)
def test_e2e_try_cast_queries(create_session, base_url, test_name, sql_query, expected_size):
"""Parameterized E2E test for various try_cast SQL queries."""
session = create_session
url = base_url
org_id = "default"
# Define time range for the query
now = datetime.now(timezone.utc)
end_time = int(now.timestamp() * 1000000)
one_min_ago = int((now - timedelta(minutes=1)).timestamp() * 1000000)
# Query data
json_data = {
"query": {
"sql": sql_query,
"start_time": one_min_ago,
"end_time": end_time,
"from": 0,
"size": expected_size,
"quick_mode": False,
"sql_mode": "full"
}
}
# Send POST request with the session
response = session.post(f"{url}api/{org_id}/_search?type=logs", json=json_data)
# Assert that the response status is 200
assert response.status_code == 200, f"{test_name} failed: Expected status 200, got {response.status_code} - {response.content}"