Skip to content
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

[exporter/clickhouse] Update default logs table schema #33611

Merged
merged 3 commits into from
Jun 19, 2024

Conversation

SpencerTorres
Copy link
Member

Description:

Closes #32215

This PR updates the default otel_logs table schema.
The intent of this change is to provide a good starting point for users to create their own schema. This schema works as-is, but should be tuned to fit the final workflow when querying (specifically the indices, TTL, and ORDER BY).

There are no breaking changes, this schema is compatible with the previous INSERT statement. This does not affect existing users, only new users that have create_schema enabled in the config.

Notable changes:

  • 2 new Timestamp columns have been added for Date and DateTime types. Nanoseconds Timestamp is preserved. This does not affect the INSERT since these are derived by DEFAULT from Timestamp.
  • Partitioning has been optimized to use a larger time range, based on the new TimestampDate time
  • TTL is now based on TimestampTime
  • Data types for TraceFlags and SeverityNumber have been reduced to a UInt8, since this is all that is required by the OTel specification.
  • String-like columns have been changed to LowCardinality where appropriate
  • ORDER BY has been reduced to only TimestampDate and TimestampTime. This offers good performance as-is, but if you have a specific workflow that depends on ServiceName for example, feel free to add it at as the first column.
  • Updated the TTL expression generator, dependent functions will need to convert to DateTime type manually (dependent code has been updated for this)

Link to tracking Issue:

Testing:

  • Updated integration tests to include new timestamp columns
    Integration tests are disabled, but I fixed them locally to test that this change works as intended.
    Unit tests are passing as well.

Documentation:

  • Updated README quick-start queries to use the more efficient TimestampTime column
  • Example DDL has been updated

) ENGINE = %s
PARTITION BY toYYYYMM(TimestampDate)
ORDER BY (TimestampDate, TimestampTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general LGTM. just wondering ORDER BY (TimestampDate, TimestampTime) may not better than ORDER BY ServiceName, SeverityText, toUnixTimestamp(Timestamp), beacause ServiceName and SeverityText( also as well-known logLevel) is the most common filter when query service log, can you write more text explain why remove them? thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be difficult to model a decent table that works for everyone (consider issues like #32215)

The idea behind this change is to simply make time range queries work as best they can. Every log has a timestamp, but not always a proper ServiceName or Severity*. Some OTel data isn't composed very well. SeverityText might not be as good as SeverityNumber, and if we try to add all of these to ORDER BY then it starts to lose its purpose as a primary index.

For those who will be using this exporter in production, the goal is to have them use this as a starting point, and then add the appropriate columns to the ORDER BY depending on their primary column. For example, look at how this blog post chooses to use PodName and Timestamp:

ORDER BY (PodName, Timestamp)

What we've found is that a lot of these values are not necessary in the order by, especially ones after the Timestamp* columns (such as TraceId in the current version). Most log queries are going to be in a tight range of time (5, 15, 30, 60 minutes) and these smaller ORDER BY clauses favor this. Again, you can always go a step further by adding your preferred column to the start of it, such as ServiceName, SeverityText, PodName, or some combination of these.

The goal is to have a good default that is easy for others to expand on for their own deployment, while also still giving a good default for those who don't bother to configure one. If you're at the scale where this schema becomes a problem, you would already be using your own schema.

Copy link
Member

@hanjm hanjm Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceName is a required in spec. https://opentelemetry.io/docs/specs/semconv/resource/#service. to say the least, ServiceName is needed in order by columns. see also as #31670

in PodName blog case , i think most common usage query pattern is PodName like xxx%, not PodName= xxx, mostly query a workload log, not the specific pod log. actually, use a serviceName as workload name will be more reasonaly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reasonable enough since it is a default schema, and if someone needs to change it they're free to do so for their deployment.

As you suggested, I have added ServiceName to the default schema.

Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we similarly update other metrics/traces tables?

@dmitryax dmitryax merged commit 2c274ba into open-telemetry:main Jun 19, 2024
154 checks passed
@github-actions github-actions bot added this to the next release milestone Jun 19, 2024
@SpencerTorres
Copy link
Member Author

Should we similarly update other metrics/traces tables?

Absolutely, but they will need to be evaluated separately (especially metrics)

@SpencerTorres SpencerTorres deleted the update-logs-schema branch June 21, 2024 02:03
andrzej-stencel pushed a commit that referenced this pull request Jul 3, 2024
…33615)

**Description:**

*NOTE: Depends on merging of #33611, #33614, and #33648*

Logs configuration is unlikely to change further with the new
recommendation of [manual schema
config](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/clickhouseexporter#schema-management).
The logs component of the exporter has proven stability, as seen in
deployments such as [ClickHouse's
Loghouse](https://clickhouse.com/blog/building-a-logging-platform-with-clickhouse-and-saving-millions-over-datadog).

With these points in mind, I suggest we upgrade the status to `beta` for
logs. Traces and metrics can remain `alpha` for now.

**Documentation:**
- Updated metadata.yaml
- Updated README
- Small unrelated change: added/refactored a section that covers tool
visualization
mx-psi pushed a commit that referenced this pull request Aug 6, 2024
**Description:**

Previously updated in #33611, I am opening this to start a discussion on
further improvements that can be made to the table.

Notable changes:
- Changed from monthly partitions to daily. With
`ttl_only_drop_parts=1`, this will help drop data for TTLs shorter than
1 month (such as when your log retention is only 7 days).
- Changed `idx_body` granularity to `8`, which should reduce the index
size (especially beneficial for cloud services with separate storage)
- Removed `TimestampDate` column
- Simplified primary key to only use `TimestampTime`. Performance
difference is negligible if not better. Also makes queries easier to
write-- with the current version it requires that you provide both
`TimestampDate` and `TimestampTime` for optimal sorting performance.
- Separated and updated order by. Now it matches the primary key, with
the addition of `Timestamp`, so that nanoseconds sorting is preserved by
default.

Let me know if you have any more suggestions.

**Link to tracking Issue:** <Issue number if applicable>

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClickHouse Logs table sub-optimal primary key (SeverityNumber vs SeverityText)
5 participants