Skip to content

Add delete log index to public API #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-03-06 18:30:02.590608",
"spec_repo_commit": "fb234cde"
"regenerated": "2025-03-06 19:05:46.129456",
"spec_repo_commit": "b892dbfc"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-03-06 18:30:02.607794",
"spec_repo_commit": "fb234cde"
"regenerated": "2025-03-06 19:05:46.145051",
"spec_repo_commit": "b892dbfc"
}
}
}
41 changes: 41 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28758,6 +28758,47 @@ paths:
permissions:
- logs_modify_indexes
/api/v1/logs/config/indexes/{name}:
delete:
description: 'Delete an existing index from your organization. Index deletions
are permanent and cannot be reverted.

You cannot recreate an index with the same name as deleted ones.'
operationId: DeleteLogsIndex
parameters:
- description: Name of the log index.
in: path
name: name
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/LogsIndex'
description: OK
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/LogsAPIErrorResponse'
description: Not Found
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
summary: Delete an index
tags:
- Logs Indexes
x-permission:
operator: OR
permissions:
- logs_modify_indexes
get:
description: Get one log index from your organization. This endpoint takes no
JSON arguments.
Expand Down
15 changes: 15 additions & 0 deletions examples/v1_logs-indexes_DeleteLogsIndex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Delete an index returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_logs_indexes::LogsIndexesAPI;

#[tokio::main]
async fn main() {
let configuration = datadog::Configuration::new();
let api = LogsIndexesAPI::with_config(configuration);
let resp = api.delete_logs_index("name".to_string()).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
115 changes: 115 additions & 0 deletions src/datadogV1/api/api_logs_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ pub enum CreateLogsIndexError {
UnknownValue(serde_json::Value),
}

/// DeleteLogsIndexError is a struct for typed errors of method [`LogsIndexesAPI::delete_logs_index`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteLogsIndexError {
APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
LogsAPIErrorResponse(crate::datadogV1::model::LogsAPIErrorResponse),
UnknownValue(serde_json::Value),
}

/// GetLogsIndexError is a struct for typed errors of method [`LogsIndexesAPI::get_logs_index`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -276,6 +285,112 @@ impl LogsIndexesAPI {
}
}

/// Delete an existing index from your organization. Index deletions are permanent and cannot be reverted.
/// You cannot recreate an index with the same name as deleted ones.
pub async fn delete_logs_index(
&self,
name: String,
) -> Result<crate::datadogV1::model::LogsIndex, datadog::Error<DeleteLogsIndexError>> {
match self.delete_logs_index_with_http_info(name).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}

/// Delete an existing index from your organization. Index deletions are permanent and cannot be reverted.
/// You cannot recreate an index with the same name as deleted ones.
pub async fn delete_logs_index_with_http_info(
&self,
name: String,
) -> Result<
datadog::ResponseContent<crate::datadogV1::model::LogsIndex>,
datadog::Error<DeleteLogsIndexError>,
> {
let local_configuration = &self.config;
let operation_id = "v1.delete_logs_index";

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v1/logs/config/indexes/{name}",
local_configuration.get_operation_host(operation_id),
name = datadog::urlencode(name)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());

// build headers
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));

// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};

// build auth
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};

local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;

let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);

if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV1::model::LogsIndex>(&local_content) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<DeleteLogsIndexError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}

/// Get one log index from your organization. This endpoint takes no JSON arguments.
pub async fn get_logs_index(
&self,
Expand Down
14 changes: 14 additions & 0 deletions tests/scenarios/features/v1/logs_indexes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ Feature: Logs Indexes
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
Scenario: Delete an index returns "Not Found" response
Given new "DeleteLogsIndex" request
And request contains "name" parameter from "REPLACE.ME"
When the request is sent
Then the response status is 404 Not Found

@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
Scenario: Delete an index returns "OK" response
Given new "DeleteLogsIndex" request
And request contains "name" parameter from "REPLACE.ME"
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
Scenario: Get all indexes returns "OK" response
Given new "ListLogIndexes" request
Expand Down
6 changes: 6 additions & 0 deletions tests/scenarios/features/v1/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,12 @@
"type": "unsafe"
}
},
"DeleteLogsIndex": {
"tag": "Logs Indexes",
"undo": {
"type": "idempotent"
}
},
"GetLogsIndex": {
"tag": "Logs Indexes",
"undo": {
Expand Down
28 changes: 28 additions & 0 deletions tests/scenarios/function_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,9 @@ pub fn collect_function_calls(world: &mut DatadogWorld) {
world
.function_mappings
.insert("v1.CreateLogsIndex".into(), test_v1_create_logs_index);
world
.function_mappings
.insert("v1.DeleteLogsIndex".into(), test_v1_delete_logs_index);
world
.function_mappings
.insert("v1.GetLogsIndex".into(), test_v1_get_logs_index);
Expand Down Expand Up @@ -7652,6 +7655,31 @@ fn test_v1_create_logs_index(world: &mut DatadogWorld, _parameters: &HashMap<Str
world.response.code = response.status.as_u16();
}

fn test_v1_delete_logs_index(world: &mut DatadogWorld, _parameters: &HashMap<String, Value>) {
let api = world
.api_instances
.v1_api_logs_indexes
.as_ref()
.expect("api instance not found");
let name = serde_json::from_value(_parameters.get("name").unwrap().clone()).unwrap();
let response = match block_on(api.delete_logs_index_with_http_info(name)) {
Ok(response) => response,
Err(error) => {
return match error {
Error::ResponseError(e) => {
world.response.code = e.status.as_u16();
if let Some(entity) = e.entity {
world.response.object = serde_json::to_value(entity).unwrap();
}
}
_ => panic!("error parsing response: {error}"),
};
}
};
world.response.object = serde_json::to_value(response.entity).unwrap();
world.response.code = response.status.as_u16();
}

fn test_v1_get_logs_index(world: &mut DatadogWorld, _parameters: &HashMap<String, Value>) {
let api = world
.api_instances
Expand Down
Loading