Skip to content

Conversation

@martijnvg
Copy link
Member

@martijnvg martijnvg commented Jan 23, 2025

Add LogsPatternUsageService that records whether there are data streams matching with logs-*-* pattern. This is recorded via the new logsdb.prior_logs_usage cluster setting. Upon upgrade to 9.x this can be used to determine whether logsdb should be enabled by default if cluster.logsdb.enabled hasn't been set.

The recommended upgrade path to 9.x is always to go to 8.latest. This component will run in clusters with version greater than 8.18.0 but not on 9.0 and newer.

Note that a follow change is required that removes / disables LogsPatternUsageService in main. Additionally updating the default of the LogsDBPlugin.CLUSTER_LOGSDB_ENABLED setting:

public static final Setting<Boolean> CLUSTER_LOGSDB_ENABLED = Setting.boolSetting(
        "cluster.logsdb.enabled",
        settings -> {
            if (LOGSDB_PRIOR_LOGS_USAGE.exists(settings)) {
                return Boolean.FALSE.toString();
            } else {
                return Boolean.TRUE.toString();
            }
        },
        Setting.Property.Dynamic,
        Setting.Property.NodeScope
    );

Add LogsPatternUsageService that records whether there are data streams matching with logs-*-* pattern. This is recorded via logsdb.prior_logs_usage cluster setting. Upon upgrade to 9.x this can be used to determine whether logsdb should be enabled by default if cluster.logsdb.enabled hasn't been set.
@martijnvg martijnvg changed the title LogsPatternUsageService Record whether data streams for logs-*-* exist for logsdb enablement in 9.x Jan 23, 2025
@martijnvg martijnvg marked this pull request as ready for review January 23, 2025 15:17
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

import java.util.function.Supplier;

/**
* A component that check in the background whether there are data streams that match log-*-* pattern and if so records this as persistent
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: checks*


/**
* A component that check in the background whether there are data streams that match log-*-* pattern and if so records this as persistent
* setting in cluster state. If logs-*-* data stream usage has been found then this component will no longer in the background.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: no longer run

@martijnvg martijnvg force-pushed the LogsPatternUsageService branch from 0486afe to 85f1c6b Compare January 24, 2025 09:08

var clusterService = services.clusterService();
Supplier<Metadata> metadataSupplier = () -> clusterService.state().metadata();
var historicLogsUsageService = new LogsPatternUsageService(services.client(), settings, services.threadPool(), metadataSupplier);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider initializing in the constructor and calling an init function here, similar to LogsdbIndexModeSettingsProvider.

Supplier<Metadata> metadataSupplier = () -> clusterService.state().metadata();
var historicLogsUsageService = new LogsPatternUsageService(services.client(), settings, services.threadPool(), metadataSupplier);
clusterService.addLocalNodeMasterListener(historicLogsUsageService);
clusterService.addLifecycleListener(new LifecycleListener() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a function in LogsPatternUsageService to construct and return a listener?

*/
final class LogsPatternUsageService implements LocalNodeMasterListener {

private static final String LOGS_PATTERN = "logs-*-*";
Copy link
Contributor

Choose a reason for hiding this comment

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

Deduplicate with LogsdbIndexModeSettingsProvider.LOGS_PATTERN ?

private static final Logger LOGGER = LogManager.getLogger(LogsPatternUsageService.class);
static final Setting<TimeValue> USAGE_CHECK_PERIOD = Setting.timeSetting(
"logsdb.usage_check.period",
new TimeValue(24, TimeUnit.HOURS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment explaining how this value is picked.

new TimeValue(24, TimeUnit.HOURS),
Setting.Property.NodeScope
);
static final Setting<Boolean> LOGSDB_PRIOR_LOGS_USAGE = Setting.boolSetting(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to restrict this as internal? Or, maybe allow updates in case we get it wrong?

At any rate, let's document expectations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only index settings can be made internal/private. Not node/ cluster settings.

I think we shouldn't document this setting. If someone sets this setting, then they might just as well configure cluster.logsdb.enabled? The advantage of this being public, is that for debugging purposes we can see that a 8.18 cluster is the right state to upgrade.

I will add a comment on top of this setting constant.

}

void scheduleNext(TimeValue waitTime) {
if (isMaster && hasPriorLogsUsage == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, if the master changes, we may miss an update in 24h? Worth documenting, though this seems fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this wait time logic a bit via this commit: e0a5c11

.actionGet();
assertThat(response.persistentSettings().get("logsdb.prior_logs_usage"), equalTo("true"));
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test for a non-matching pattern?

Also, is it possible to test that it only applies to master and it no longer runs after setting to true?

Copy link
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

…elected.

Changed `logsdb.usage_check.period` to `logsdb.usage_check.max_period` and
starting to check 60s after node has been elected as master. This gets doubled
after each check that doesn't see any log-*-* usage upto `logsdb.usage_check.max_period` (defaults to 24h)
@martijnvg martijnvg requested a review from kkrik-es January 27, 2025 11:10
assertThat(indexResponse.getResult(), equalTo(DocWriteResponse.Result.CREATED));

ensureGreen("log-myapp-prod");
assertBusy(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

In fairness, add a short sleep() to give time for the usage service to run?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I did this which is better than a thread.sleep() :572d670010d88ff1f1639197fe18fec7544ddf88

@martijnvg
Copy link
Member Author

@elasticmachine update branch

@martijnvg
Copy link
Member Author

@elasticmachine update branch

@martijnvg martijnvg added the auto-backport Automatically create backport pull requests when merged label Jan 28, 2025
@martijnvg martijnvg enabled auto-merge (squash) January 28, 2025 06:56
@martijnvg martijnvg merged commit 1da8285 into elastic:main Jan 28, 2025
16 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 120708

martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Jan 28, 2025
…in 9.x (elastic#120708)

Add LogsPatternUsageService that records whether there are data streams matching with logs-*-* pattern. This is recorded via the new logsdb.prior_logs_usage cluster setting. Upon upgrade to 9.x this can be used to determine whether logsdb should be enabled by default if cluster.logsdb.enabled hasn't been set.

The recommended upgrade path to 9.x is always to go to 8.latest. This component will run in clusters with version greater than 8.18.0 but not on 9.0 and newer.
martijnvg added a commit that referenced this pull request Jan 28, 2025
…ement in 9.x (#121025)

Backporting #120708 to 8.x branch.

Add LogsPatternUsageService that records whether there are data streams matching with logs-*-* pattern. This is recorded via the new logsdb.prior_logs_usage cluster setting. Upon upgrade to 9.x this can be used to determine whether logsdb should be enabled by default if cluster.logsdb.enabled hasn't been set.

The recommended upgrade path to 9.x is always to go to 8.latest. This component will run in clusters with version greater than 8.18.0 but not on 9.0 and newer.
martijnvg added a commit that referenced this pull request Jan 29, 2025
Enable logsdb by default if logsdb.prior_logs_usage has not been set to true.

Meaning that if no data streams were created matching with the logs-- pattern in 8.x, then logsdb will be enabled by default for data streams matching with logs-*-* pattern.

Also removes LogsPatternUsageService as with version 9.0 and beyond, this component is no longer necessary.

Followup from #120708
Closes #106489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >non-issue :StorageEngine/Logs You know, for Logs Team:StorageEngine v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants