Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

docs(cloudwatch): document Logs Insights subset and missing Logs actions (#2044)

武田隆志86134e8c7f98
diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index 1c7e2bf679..708fc5e0b1 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -252,7 +252,8 @@ See [Initialization Hooks](./initialization-hooks.md) for lifecycle phases and s
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_CLOUDWATCHLOGS_ENABLED` | `true` | Enable the CloudWatch Logs service |
-| `FLOCI_SERVICES_CLOUDWATCHLOGS_MAX_EVENTS_PER_QUERY` | `10000` | Maximum log events returned by a single `FilterLogEvents` call |
+| `FLOCI_SERVICES_CLOUDWATCHLOGS_MAX_EVENTS_PER_QUERY` | `10000` | Maximum log events returned by a single `FilterLogEvents` or `GetLogEvents` call, and the upper bound for a Logs Insights `limit` |
+| `FLOCI_SERVICES_CLOUDWATCHLOGS_QUERY_COMPLETION_DELAY_MS` | `0` | Artificial Logs Insights query delay. With `0` a query completes immediately; a positive value emulates the asynchronous `Running` → `Complete` lifecycle |
### CloudWatch Metrics
diff --git a/docs/services/cloudwatch.md b/docs/services/cloudwatch.md
index e22e2bb748..f52cc86068 100644
--- a/docs/services/cloudwatch.md
+++ b/docs/services/cloudwatch.md
@@ -27,13 +27,68 @@ Floci supports both CloudWatch Logs and CloudWatch Metrics.
| `TagLogGroup` | Tag a log group |
| `UntagLogGroup` | Remove tags |
| `ListTagsLogGroup` | List tags |
+| `TagResource` | Tag a log group by ARN |
+| `UntagResource` | Remove tags from a log group by ARN |
+| `ListTagsForResource` | List tags for a log group ARN |
+| `PutSubscriptionFilter` | Create or update a subscription filter (stored only, see note below) |
+| `DescribeSubscriptionFilters` | List subscription filters on a log group |
+| `DeleteSubscriptionFilter` | Delete a subscription filter |
+| `GetDataProtectionPolicy` | Return the resolved log group identifier (see note below) |
+| `StartQuery` | Start a Logs Insights query (see [Logs Insights](#logs-insights)) |
+| `GetQueryResults` | Get the status and results of a Logs Insights query |
+| `StopQuery` | Stop a query that has not completed yet |
+
+Two actions are currently simplified:
+
+- **`PutSubscriptionFilter`** stores the filter so that `DescribeSubscriptionFilters`
+ returns it, but log events are **not** forwarded to the destination ARN. Lambda,
+ Kinesis, and Firehose subscription destinations are not wired up.
+- **`GetDataProtectionPolicy`** does not model data-protection policies. It returns
+ HTTP 200 with the resolved `logGroupIdentifier` and no `policyDocument` — including for
+ a log group that does not exist, where real AWS returns `ResourceNotFoundException`.
+
+### Logs Insights {#logs-insights}
+
+`StartQuery` / `GetQueryResults` / `StopQuery` run a **subset** of the Logs Insights
+query language. Supported commands:
+
+| Command | Notes |
+|---|---|
+| `fields a, b, ...` | Projection. Defaults to `@timestamp, @message`. `display` is an alias |
+| `filter <field> = 'v'` | Equality. `!=` and `==` are also accepted; `where` is an alias |
+| `sort <field> [asc\|desc]` | `order` is an alias |
+| `dedup <field, ...>` | Keeps the first row per unique tuple, applied after sorting |
+| `limit N` | The effective cap is the smallest of this value, the `StartQuery` `limit` parameter, and `FLOCI_SERVICES_CLOUDWATCHLOGS_MAX_EVENTS_PER_QUERY` |
+
+Fields may be `@timestamp`, `@message`, `@ingestionTime`, `@ptr`, or a dotted path into
+a JSON log message (for example `level` or `params.job_id`). A `@ptr` column is always
+included in each result row, appended unless `fields` already names it.
+
+Unsupported syntax never fails the query, so it is worth knowing how each case degrades:
+
+| Input | Result |
+|---|---|
+| An unsupported command (`stats`, `parse`, ...) | Skipped with a warning in the server log. No aggregation happens |
+| A `filter` whose operator is not `=`, `!=` or `==` — for example `like /ERROR/` or `=~ /ERROR/` | The whole stage is dropped with a warning, so **every** row is returned |
+| A `filter` using `<`, `<=`, `>` or `>=` | The `=` is taken as the operator and the rest of the token becomes part of the field name, which then resolves to nothing — so the row never matches and you get **no** rows. No warning is logged |
+| A projected field that does not exist | Rendered as an empty string. No warning |
+| A `sort` direction other than `asc` / `desc` | Treated as ascending. No warning |
+
+In short, a query can come back either wider or narrower than intended without any error. When a
+result set looks wrong, check the server log for `Ignoring unsupported Logs Insights ...` — and
+note that the `>=` case above produces no log line at all.
+
+For simple substring matching, `FilterLogEvents` is the more predictable option today. Note that
+Floci matches `--filter-pattern` as a plain substring of the message; the real filter-pattern
+syntax (`?ERROR ?WARN`, `{ $.level = "ERROR" }`, and so on) is not parsed.
### Configuration
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_CLOUDWATCHLOGS_ENABLED` | `true` | Enable or disable the CloudWatch Logs service |
-| `FLOCI_SERVICES_CLOUDWATCHLOGS_MAX_EVENTS_PER_QUERY` | `10000` | Maximum events returned per `FilterLogEvents` / `GetLogEvents` call |
+| `FLOCI_SERVICES_CLOUDWATCHLOGS_MAX_EVENTS_PER_QUERY` | `10000` | Maximum events returned per `FilterLogEvents` / `GetLogEvents` call, and the upper bound for a Logs Insights `limit` |
+| `FLOCI_SERVICES_CLOUDWATCHLOGS_QUERY_COMPLETION_DELAY_MS` | `0` | Artificial Logs Insights query delay. With `0` a query completes immediately. A positive value emulates the real asynchronous lifecycle (`Running` → `Complete` after the delay), which also makes `StopQuery` on a still-running query return `success=true` |
### Examples
@@ -67,6 +122,19 @@ aws logs filter-log-events \
--filter-pattern "ERROR" \
--endpoint-url $AWS_ENDPOINT_URL
+# Run a Logs Insights query
+QUERY_ID=$(aws logs start-query \
+ --log-group-name /app/backend \
+ --start-time $(($(date +%s) - 3600)) \
+ --end-time $(date +%s) \
+ --query-string 'fields @timestamp, @message | sort @timestamp desc | limit 20' \
+ --query queryId --output text \
+ --endpoint-url $AWS_ENDPOINT_URL)
+
+aws logs get-query-results \
+ --query-id "$QUERY_ID" \
+ --endpoint-url $AWS_ENDPOINT_URL
+
# Set retention
aws logs put-retention-policy \
--log-group-name /app/backend \