diff --git a/.github/actions/check/action.yml b/.github/actions/check/action.yml index 01a4ed1d..cd281cf0 100644 --- a/.github/actions/check/action.yml +++ b/.github/actions/check/action.yml @@ -40,7 +40,7 @@ runs: - name: Run contract tests v3 if: ${{ inputs.flaky != 'true' }} - uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1 + uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests/v1 with: test_service_port: 9000 enable_persistence_tests: true diff --git a/.github/actions/publish-docs/action.yml b/.github/actions/publish-docs/action.yml index 2a99cf5d..86267459 100644 --- a/.github/actions/publish-docs/action.yml +++ b/.github/actions/publish-docs/action.yml @@ -8,7 +8,7 @@ inputs: runs: using: composite steps: - - uses: launchdarkly/gh-actions/actions/publish-pages@publish-pages-v1 + - uses: launchdarkly/gh-actions/actions/publish-pages@publish-pages/v1 name: 'Publish to Github pages' with: docs_path: docs/build/html/ diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml index 54c573b3..7a383540 100644 --- a/.github/actions/publish/action.yml +++ b/.github/actions/publish/action.yml @@ -8,7 +8,7 @@ inputs: runs: using: composite steps: - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: pattern: 'gems-*' merge-multiple: true diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 96ee9cd7..b9036114 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -19,7 +19,7 @@ runs: distribution: temurin java-version: "21" - - uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0 + - uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 with: ruby-version: ${{ inputs.version }} bundler: "4.0.19" diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..3188240d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: 'github-actions' + directories: + - '/' + - '/.github/actions/*' + schedule: + interval: 'monthly' + cooldown: + default-days: 7 + exclude: + - 'launchdarkly/*' diff --git a/.github/renovate.json b/.github/renovate.json deleted file mode 100644 index cc962478..00000000 --- a/.github/renovate.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["github>launchdarkly/gh-actions//renovate/sdk-ruby"] -} diff --git a/.github/workflows/build-gem.yml b/.github/workflows/build-gem.yml index fa70a6ea..6de6832f 100644 --- a/.github/workflows/build-gem.yml +++ b/.github/workflows/build-gem.yml @@ -26,7 +26,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: launchdarkly/gh-actions/actions/persistent-stores@persistent-stores-v0 + - uses: launchdarkly/gh-actions/actions/persistent-stores@persistent-stores/v0 with: redis: true consul: true @@ -44,7 +44,7 @@ jobs: - name: Build gemspec run: gem build launchdarkly-server-sdk.gemspec --platform=$BUILD_PLATFORM - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: ${{ inputs.upload-artifact }} with: name: gems-${{ inputs.version }} diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 654a8e72..a4bb22d2 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -35,7 +35,7 @@ jobs: version: "3.4" install-dependencies: false - - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1 + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets/v1 name: "Get rubygems API key" if: ${{ format('{0}', inputs.dry_run) == 'false' }} with: @@ -56,6 +56,6 @@ jobs: - name: Attest build provenance if: ${{ format('{0}', inputs.dry_run) == 'false' }} - uses: actions/attest@f7c74d28b9d84cb8768d0b8ca14a4bac6ef463e6 # v4.2.0 + uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-path: 'launchdarkly-server-sdk-*.gem' diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 7b32d95e..8971a38d 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -52,7 +52,7 @@ jobs: version: "3.4" install-dependencies: false - - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets-v1 + - uses: launchdarkly/gh-actions/actions/release-secrets@release-secrets/v1 name: "Get rubygems API key" with: aws_assume_role: ${{ vars.AWS_ROLE_ARN }} @@ -70,6 +70,6 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Attest build provenance - uses: actions/attest@f7c74d28b9d84cb8768d0b8ca14a4bac6ef463e6 # v4.2.0 + uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-path: 'launchdarkly-server-sdk-*.gem' diff --git a/README.md b/README.md index 6acadf29..133b7636 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ LaunchDarkly overview Supported Ruby versions ----------------------- -This version of the LaunchDarkly SDK has a minimum Ruby version of 3.4.0. On JRuby, the minimum is JRuby 10.0, which requires Java 21. +While this version of the LaunchDarkly SDK requires Ruby 3.4.0 or later (or JRuby 10.0 or later, which requires Java 21), you should use the latest patched version of a supported Ruby or JRuby release. Getting started ----------- diff --git a/contract-tests/client_entity.rb b/contract-tests/client_entity.rb index ba012107..9a88221a 100644 --- a/contract-tests/client_entity.rb +++ b/contract-tests/client_entity.rb @@ -15,6 +15,14 @@ def initialize(log, config) opts[:logger] = log + # A per-component baseUri set below takes precedence over these. + service_endpoints = config[:serviceEndpoints] + if service_endpoints + opts[:stream_uri] = service_endpoints[:streaming] if service_endpoints[:streaming] + opts[:base_uri] = service_endpoints[:polling] if service_endpoints[:polling] + opts[:events_uri] = service_endpoints[:events] if service_endpoints[:events] + end + data_system_config = config[:dataSystem] if data_system_config data_system = LaunchDarkly::DataSystem.custom @@ -91,6 +99,13 @@ def initialize(log, config) } end + if config[:wrapper] + # The harness sends an empty string for an unset name or version. + wrapper = config[:wrapper] + opts[:wrapper_name] = wrapper[:name] unless wrapper[:name].to_s.empty? + opts[:wrapper_version] = wrapper[:version] unless wrapper[:version].to_s.empty? + end + if config[:hooks] opts[:hooks] = config[:hooks][:hooks].map do |hook| Hook.new(hook[:name], hook[:callbackUri], hook[:data] || {}, hook[:errors] || {}) diff --git a/contract-tests/service.rb b/contract-tests/service.rb index 1ff98c79..684e5eab 100644 --- a/contract-tests/service.rb +++ b/contract-tests/service.rb @@ -37,6 +37,7 @@ 'migrations', 'event-gzip', 'optional-event-gzip', + 'diagnostic-events', 'event-sampling', 'context-comparison', 'polling-gzip', @@ -53,6 +54,9 @@ 'flag-change-listeners', 'flag-value-change-listeners', 'fdv1-fallback', + 'wrapper', + 'service-endpoints', + 'tls:verify-peer', ], }.to_json end diff --git a/spec/ldclient_listeners_spec.rb b/spec/ldclient_listeners_spec.rb index 2542b81e..927ffba7 100644 --- a/spec/ldclient_listeners_spec.rb +++ b/spec/ldclient_listeners_spec.rb @@ -13,8 +13,8 @@ module LaunchDarkly end it "sends status updates" do - store = MockBigSegmentStore.new - store.setup_metadata(Time.now) + store = GatedBigSegmentStore.new + store.queue_metadata(Time.now) big_segments_config = BigSegmentsConfig.new( store: store, status_poll_interval: 0.01 @@ -24,17 +24,29 @@ module LaunchDarkly expect(status1.available).to be(true) expect(status1.stale).to be(false) + # Status reads after the first come from the cache, so the second query comes from the + # poller. Observers have been notified of the first status by the time it starts, so the + # observer added below sees only later changes. + expect(store.wait_for_queries(2)).to be(true) + statuses = Queue.new observer = SimpleObserver.adding_to_queue(statuses) client.big_segment_store_status_provider.add_observer(observer) - store.setup_metadata_error(StandardError.new("sorry")) + # Fail the waiting query, then wait for the poller to start the next one. It has notified + # observers of the failure by then. + store.queue_metadata_error(StandardError.new("sorry")) + expect(store.wait_for_queries(3)).to be(true) + # The observer should have received one status, reporting the store as unavailable. + expect(statuses.size).to eq(1) status2 = statuses.pop expect(status2.available).to be(false) expect(status2.stale).to be(false) expect(client.big_segment_store_status_provider.status).to eq(status2) + ensure + store.release end end end diff --git a/spec/mock_components.rb b/spec/mock_components.rb index 4f0784c7..56a2e96d 100644 --- a/spec/mock_components.rb +++ b/spec/mock_components.rb @@ -223,6 +223,87 @@ def setup_segment_for_context(user_key, segment, included) end end + # + # A Big Segment store whose metadata queries wait for the test to supply each result. + # + # The status poller notifies observers of one result before it starts its next query. Once a + # test sees a query start, every earlier result has been delivered, and the poller stays in that + # query until the test supplies another result. + # + # Call {#release} before closing the client. The poller cannot stop while a query is waiting. + # + class GatedBigSegmentStore + def initialize + @lock = Mutex.new + @changed = ConditionVariable.new + @results = [] + @last_result = nil + @queries_started = 0 + @released = false + end + + def get_metadata + result = @lock.synchronize do + @queries_started += 1 + @changed.broadcast + @changed.wait(@lock) while @results.empty? && !@released + @last_result = @results.shift unless @results.empty? + @last_result + end + raise result if result.is_a?(Exception) + result + end + + def get_membership(_context_hash) + nil + end + + def stop + end + + # Supplies the result of the next metadata query. + def queue_metadata(last_up_to_date) + queue_result(Interfaces::BigSegmentStoreMetadata.new(last_up_to_date.to_f * 1000)) + end + + # Makes the next metadata query raise the given error. + def queue_metadata_error(ex) + queue_result(ex) + end + + # + # Blocks until the store has received `count` metadata queries, or until the timeout passes. + # + # @return [Boolean] false if the queries did not start within the timeout + # + def wait_for_queries(count, timeout: 5) + deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout + @lock.synchronize do + while @queries_started < count + remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC) + return false if remaining <= 0 + @changed.wait(@lock, remaining) + end + true + end + end + + # Stops queries from waiting. Waiting and later queries return the last result again. + def release + @lock.synchronize do + @released = true + @changed.broadcast + end + end + + private def queue_result(result) + @lock.synchronize do + @results << result + @changed.broadcast + end + end + end + class SimpleObserver def initialize(fn) @fn = fn