Pass reconciliation ENV vars into Rails API and send to Agent During Reconcilition flow

MR - Add Full & Partial Reconciliation Interval From... (!152878 - merged)

Description

With new settings section passed into the reconcilation API, on the rails side, we should pass the ENV values into the API and send them to the agent during the reconciliation flow.

Acceptance Criteria

  • The settings with 2 fields are injected into the API, and get the value from the settings we passed into the reconciler main class
  • a new class for handling the validation and injecting values. pls note this design is going to be reused multiple times in the furture as we plan to relocate and add more settings from rails to the agent using this design.
  • Have proper unit testing coverage and e2e testing

Technical Requirements

Given that I am new to this repo, I have tested locally with all the below arguments, and it should be the valid case.

The settings are already passed into the main class as the params, then we would need to define a new class for injecting the value from settings into the returned payload.

And for the Result chain we use, settings field has always been available from start to the end.

          result =
            initial_result
              .and_then(Input::ParamsValidator.method(:validate))
              .map(Input::ParamsExtractor.method(:extract))
              .map(Input::ParamsToInfosConverter.method(:convert))
              .map(Input::AgentInfosObserver.method(:observe))
              .map(Persistence::WorkspacesFromAgentInfosUpdater.method(:update))
              .map(Persistence::OrphanedWorkspacesObserver.method(:observe))
              .map(Persistence::WorkspacesToBeReturnedFinder.method(:find))
              .map(Output::WorkspacesToRailsInfosConverter.method(:convert))
              .map(Persistence::WorkspacesToBeReturnedUpdater.method(:update))
              .map(Output::RailsInfosObserver.method(:observe))
              .map(
                # As the final step, return the workspace_rails_infos in a WorkspaceReconcileSuccessful message
                ->(value) do
                  RemoteDevelopment::Messages::WorkspaceReconcileSuccessful.new(
                    workspace_rails_infos: value.fetch(:workspace_rails_infos)
                  )
                end
              )

The only place we get rid of the settings, in at the end map. We only select workspace_rails_infos to return.

RemoteDevelopment::Messages::WorkspaceReconcileSuccessful.new(
                    workspace_rails_infos: value.fetch(:workspace_rails_infos)
                  )

The current thinking is to have a new class for converting Rails settings to agent settings. Pls see interface below. This class is responsible for grabbing the Rails settings from values and then return expected payload for the agent settings we return

# frozen_string_literal: true

module RemoteDevelopment
    module Workspaces
      module Reconcile
        module Output
          class SettingsToAgentSettingsConverter
            # include UpdateTypes
  
            # @param [Hash] value
            # @return [Hash]
            def self.convert(value);end
  
          end
        end
      end
    end
  end

In the Result chain, this class could be injected either before or after we finish everything with RailsInfos, as those 2 fields are separated and irrelavant. And my preference is to have the class after .map(Output::RailsInfosObserver.method(:observe)).

Also we would add additional logging, and I will rename the existing Output::RailsInfosObserver into Output::DataReturnedForAgentObserver, and add in extra logging for settings with both intervals.

Also, I have added in additional validation into the settings module, which will raise exception when loading the settings env, and any value is invalid. Pls see MR above for more details

Design Requirements

No UI required

Impact Assessment

  • Instance admins may want to override these values to either provide faster update and reconciliation for workspaces, or to reduce load on the monolith.
  • Developers may want to override these values so they can have faster feedback when developing features, e.g. have a much faster full reconciliation interval than an hour. Otherwise they have to hack the hardcoded intervals, or restart their agent to force a full reconcile.
Edited by zli