Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Document the state by adding a label to the FLIP page with one of "discussion", "accepted", "released", "rejected".

Page properties
Discussion threadPrepare the FLIP
Vote threadJIRARelease

[This FLIP proposal is a joint work between  Rui Fan and Samrat Deb  ]

Table of Contents

...


Discussion threadhttps://lists.apache.org/thread/kmm03gls1vw4x6vk1ypr9ny9q9522495
Vote threadhttps://lists.apache.org/thread/3wmhhqgkkg1l7ncxnzwqnjqyhqz545gl
JIRA

Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyFLINK-32723

Releaseflink-kubernetes-operator 1.7.0



Table of Contents

1. Motivation

The proposal to introduce autoscaling for Flink (FLIP-271) has garnered significant interest due to its potential to greatly enhance the usability of Flink. The primary objective is to enable users to effortlessly enable the autoscaler for their Flink jobs without the need for intricate parallelism configurations. However, the current implementation of the flink-autoscaler is tightly integrated coupled with Kubernetes and resides within the flink-kubernetes-operator repository.

There are compelling reasons to extend the usage use of the flink-autoscaler to more types of Flink jobs running on YARN as well:

  1. With the recent merge of the Externalized Declarative Resource Management (FLIP-291, FLINK-31316), in-place scaling is now supported across all types of Flink jobs. This development has made scaling Flink on YARN a straightforward process.

  2. Several discussions within the Flink user community, as observed in the mail list , have emphasized the necessity of flink-autoscaler supporting Flink on YARN.

Hence, this FLIP is centered around the crucial task of decoupling the autoscaler functionality from Kubernetes.
By achieving this decoupling, we aim to empower Flink users to leverage the benefits of autoscaling irrespective of their chosen deployment platform, whether it be Kubernetes or YARN.

2. Core Idea

  1. JobAutoScaler and JobAutoScalerImpl: These components will define the general generic autoscaling strategy for Flink jobs and are essential for the implementation of the autoscaler module.

  2. Interfaces: The FLIP outlines the necessity of defining a few interfaces - ScalingRealizer, AutoScalerEventHandler, AutoScalerStateStore and AutoScalerStateStoreFactory and AutoScalerStateStore.
    1. The ScalingRealizer interface handles scaling action.
    2. The AutoScalerEventHandler  interface handles
    event-based operations, while the
    1. loggable events.
    2. The AutoScalerStateStore  interface is responsible for accessing and persisting the autoscaler's state.

  3. Dependencies: The autoscaler module should not rely on any Kubernetesbe agnostic to any specific deployment framework like Kubernetes, YARN etc. Currently, core autoscaling framework closely coupled with Kubernetes-related dependencies such as fabric8, flink-kubernetes-operator, or flink-kubernetes. 
    InsteadIdeally, it can should rely on Apache Flink project dependencies to gather metrics and make scaling decisions based on JobVertexID , Configuration , MetricGroup , and other relevant classes.

  4. Optional Goal: As a nice-to-have feature, the FLIP proposes moving the flink-autoscaler module to the Apache Flink repository, thereby making it an integral part of the Flink project.
    Please note that, Initially autoscaler module will be part of For flink-autoscaler module, we prefer stay it at flink-k8s-operator first(Advance discussion with Gyula Fora).

        a. Since the autoscaler is not only compatible with the latest Flink version, moving it to the Flink repository may not be the most suitable option.
            It would need to function across various Flink versions, potentially necessitating a separate repository/subproject. 

        b. Removing the autoscaler from the flink-kubernetes-operator repository

    during this FLIP, and we can move the autoscaler module to apache flink in the last step of this FLIP.

Note:
Independent flink-kubernetes-operator-autoscaler  module is not necessary. Moving classes to flink-kubernetes-operator  will reduce complexity. We can discuss it in the mail list.

Why it isn't necessary?

...

  1. would introduce significant operational overhead and complicate the release process,
            which would be viewed negatively from the operator's perspective.

    Therefore, considering above two points preference is to retain core autoscaler framework/logic within the flink-kubernetes-operator as a submodule in the short term. Should it prove to be stable in the future,
    we can revisit the idea of relocating it. As it stabilizes, the release frequency will decrease, and this transition will have a minor impact on the operator.


Note:
Independent flink-kubernetes-operator-autoscaler 

...

module is not necessary. Moving classes to flink-kubernetes-operator 

...

will reduce complexity.

Why flink-kubernetes-operator-autoscaler as seperate module isn't necessary?
     If flink-kubernetes-operator-autoscaler  as an independent module, it must depend on flink-kubernetes-operator  module. flink-kubernetes-operator  cannot depend on
     flink-kubernetes-operator-autoscaler , so it's more difficult to load these classes than remove the flink-kubernetes-operator-autoscaler  module.

...

flink-kubernetes-operator-autoscaler 
     just defines KubernetesScalingRealizer, KubernetesAutoScalerEventHandler and KubernetesAutoScalerStateStore.
     There are not many of these classes, so moving them to flink-kubernetes-operator  will reduce complexity. 

3. Public Interfaces

3.1 JobAutoScaler

Public Interfaces

...

The proposed interface retains similarity maintains a resemblance to the existing JobAutoScaler, although albeit with modified adjustments to its method parameters. Instead In lieu of using employing Kubernetes-related specific classes, the parameters will be replaced substituted with
JobAutoScalerContext<KEY, INFO> . To enhance clarity, it is suggested to rename the generic parameter KEY  to JOB_KEY . The autoscaler will treat Flink jobs with the same jobKey as identical.
The generic INFO will be introduced later. JobAutoScalerContext<KEY> , rendering it framework-agnostic, suitable for various deployment frameworks beyond Kubernetes.

The 'KEY' in this context corresponds to the 'jobKey', and when two instances share the same 'KEY,' they are regarded as representing the same Flink job.

Code Block
/**
 * The generic Autoscaler.
 *
 * @param <KEY> The job key.
 */
@Internal
Code Block
/** The general Autoscaler instance. */
public interface JobAutoScaler<KEY, INFO>Context extends JobAutoScalerContext<KEY>> {

    /** Called as part of the reconciliation loop. Returns true if this call led to scaling. */
    booleanvoid scale(JobAutoScalerContext<KEY, INFO>Context context);

 throws Exception;

    /** Called when the job is deleted. */
    void cleanup(JobAutoScalerContext<KEY, INFO> context);

    /** Get the current parallelism overrides for the job. */
    Map<String, String> getParallelismOverrides(JobAutoScalerContext<KEY, INFO> contextKEY key);
}

3.2

...

JobAutoScalerContext

The JobAutoScalerContext  encapsulates essential information required plays a pivotal role in consolidating crucial information necessary for scaling Flink jobs, including . It encompasses essential data such as the jobKey, jobId, stateStoreconfiguration, MetricGroup, and INFO extraJobInfomore.

Currently , in the existing code or for Kubernetes jobsas of now, the jobKey is defined as using io.javaoperatorsdk.operator.processing.event.ResourceID .
However, there is a possibility to define the jobKey for Flink jobs running on YARN in the future. , as seen in the existing code and for Kubernetes jobs. However, it's important to note that there may be potential future developments where the jobKey for Flink jobs operating on YARN could differ.

The JobAutoScalerContext , encompassing all pertinent details, will be furnished to these implementations. This comprehensive context will be provided Regarding the INFO extraJobInfo, it is worth noting that the flink-autoscaler itself does not utilize this information. Instead, it is employed by certain implementations of the AutoScalerEventHandler.
The entire JobAutoScalerContext, comprising all relevant details, will be passed to these implementations when the autoscaler invokes their respective callbacks.

...

Code Block
/**
 * The job autoscaler context.
 , it includes all details related to the current job.
 *
 * @param <KEY>
 *The @paramjob <INFO>key.
 */
@Experimental
@AllArgsConstructor
@ToString
public class JobAutoScalerContext<KEY,JobAutoScalerContext<KEY> INFO> {

    //** The identifier of each flink job. */
    @Getter private final KEY jobKey;

    @Getter/** privateThe finaljobId JobID jobID;

    // Whetherand jobStatus can be null when the job is really running, the STARTING or CANCELING aren't running.
   isn't started. */
    @Nullable @Getter private final JobID jobID;

    @Nullable @Getter private final booleanJobStatus isRunningjobStatus;

    @Getter private final Configuration confconfiguration;

    @Getter private final MetricGroup metricGroup;

    @ToString.Exclude
    private final SupplierWithException<RestClusterClient<String>, Exception> restClientSupplier;

    public @GetterRestClusterClient<String> privategetRestClusterClient() finalthrows DurationException flinkClientTimeout;{

     private final AutoScalerStateStoreFactory stateStoreFactory;
 return restClientSupplier.get();
    }
}

3.3 ScalingRealizer

The ScalingRealizer interface is responsible for managing scaling actions(upscale or downscale), and specifically, the ScalingRealizer#realize  method will be invoked from JobAutoscaler#scale  function.

Code Block
/**
 * The Scaling Realizer *is Theresponsible flink-autoscaler doesn't use the extraJobInfo, it is only used in some implements. This
     * whole context will be passed to these implements when the autoscaler callbacks them.for managing scaling actions.
 *
 * @param <KEY> The job key.
 * @param <Context> Instance of JobAutoScalerContext.
 */
@Experimental
public interface ScalingRealizer<KEY, Context extends JobAutoScalerContext<KEY>> {

     /**/
 Update job's parallelism @Getterto @Nullable private final INFO extraJobInfo;

parallelismOverrides. */
    publicvoid RestClusterClient<String> getRestClusterClientrealize()Context throwscontext, ExceptionMap<String, {
        return restClientSupplier.get(String> parallelismOverrides);
    }

    public Optional<AutoScalerStateStore> getStateStore() {
        return stateStoreFactory.get();
    }

    public AutoScalerStateStore getOrCreateStateStore() {
        return stateStoreFactory.getOrCreate();
    }
}

3. AutoScalerEventHandler

}


3.4 AutoScalerEventHandler

The AutoScalerEventHandler interface is responsible for managing loggable events, and specifically, the AutoScalerEventHandler#handleEvent  method will be invoked by the auto scaler when there's a need to handle such events. These events might include scaling errors, reporting scaling results, and more.

It's important to note that the AutoScalerEventHandler object is shared across all Flink jobs and doesn't possess specific job information. That's precisely why the JobAutoScalerContext is passed as a parameter to the handleEvent  method, allowing it to access the necessary job-related details when handling eventsAutoScalerEventHandler  will be called by auto scaler when some cases need to be handle, such as: scaling error, report scaling result and update flink job based on the recommended parallelism.
For current code or kubernetes job, most of handlers will record event, all of handlers needs the AbstractFlinkResource , it's saved at INFO extraJobInfo  of JobAutoScalerContext .
The AutoScalerEventHandler  object is shared for all flink jobs, it doesn't have the job information. However, it needs the AbstractFlinkResource  of every job, that's why adding the INFO extraJobInfo  to the JobAutoScalerContext .


Code Block
/**
 * Handler all loggable events during scaling.
 *
 * @param <KEY>
  The job key.
 * @param <INFO><Context> Instance of JobAutoScalerContext.
 */
@Experimental
public interface AutoScalerEventHandler<KEY, INFO>Context extends JobAutoScalerContext<KEY>> {

    void handlerScalingFailure(/**
     * Handle the event.
    JobAutoScalerContext<KEY, INFO> context, *
     * @param interval When interval is great FailureReasonthan failureReason0,
 events that repeat within the interval will be
    String errorMessage);

 *     void handlerScalingReport(JobAutoScalerContext<KEY, INFO> context, String scalingReportMessage);
ignored.
     */
    void handlerRecommendedParallelismhandleEvent(
            JobAutoScalerContext<KEY, INFO>Context context,
 Map<String, String> recommendedParallelism);

    /** The reason of autoscaler failure. */Type type,
    enum FailureReason {
      String  ScalingException(true)reason,
          IneffectiveScaling(false);

  String message,
     // true indicates that the current reason is@Nullable anString unexpectedmessageKey,
 error. False indicates that the
       @Nullable // current reason is that the strategy causes this scaling to fail.Duration interval);

    /** The type of the events. */
    enum    private final boolean isError;
Type {
        FailureReason(boolean isError) {Normal,
            this.isError = isError;
 Warning
       }

        public boolean isError() {
            return isError;
        }
    }
}

4. AutoScalerStateStore

...

}
}


3.5 AutoScalerStateStore

The AutoScalerStateStore serves the crucial role of persisting and providing access to state information during the scaling process.

In the existing code and for Kubernetes jobs, this state is stored in a ConfigMap . Consequently, the KubernetesAutoScalerStateStore  is responsible for retrieving the ConfigMap before the scaling operation and preserving it after the scaling event.

However, for other types of jobs, such as those running on YARN or in standalone mode, the default behavior involves persisting scaling information in memory itself via introducing new implementation InMemoryAutoScalerStateStore . It's important to note that, in the future, there is the possibility to pesist in RDBMS or any persistent storage. It can be new implementation such as JdbcAutoScalerStateStore  etc  to ensure persistent storage of the state.


These method parameters of AutoScalerStateStore to the specific class instead of String, such as: Map<JobVertexID, SortedMap<Instant, ScalingSummary>> scalingHistory. So, all state store stores are responsible for the serialization, deserialization and state store.


Code Block
/**
 * The state store is responsible for storing all state during scaling.
 *
 * @param <KEY> The job key.
 * @param <Context> Instance of JobAutoScalerContext.
 */
@Experimental
public interface AutoScalerStateStore<KEY, Context extends JobAutoScalerContext<KEY>> {
Code Block
/** It will be used store state during scaling. */
public interface AutoScalerStateStore {

    Optional<String> get(String key);

    // Put the state to state store, please flush the state store to prevent the state lost.
    void putstoreScalingHistory(String key, String value);


            Context jobContext, Map<JobVertexID, SortedMap<Instant, ScalingSummary>> scalingHistory)
      void remove(String key);

    voidthrows flush()Exception;

    /**
  Optional<Map<JobVertexID, SortedMap<Instant, ScalingSummary>>> *getScalingHistory(
 The state store cannot be used if the state store isn't valid. Please create a new state   Context jobContext) throws Exception;

    void removeScalingHistory(Context jobContext) throws Exception;

    void *storeEvaluatedMetrics(
   store by {@link AutoScalerStateStoreFactory}.
     */
 Context jobContext, SortedMap<Instant, booleanCollectedMetrics> isValid(evaluatedMetrics);
}

Currently, the AutoScalerStateStore is maintained by AutoscalerInfoManager to reduce the access with kubernetes. If the state store isn't vaild, AutoscalerInfoManager will get or create a new AutoScalerStateStore.

Proposed Changes

...

The FlinkService is related to kubernetes, so we shouldn't use it.The RestClusterClient is general flink client, it supports all flink types, including: kubernetes, yarn, standalone.
The RestClusterClient<String> is included in JobAutoScalerContext.

...


            throws Exception;

    Optional<SortedMap<Instant, CollectedMetrics>> getEvaluatedMetrics(Context jobContext)
            throws Exception;

    void removeEvaluatedMetrics(Context jobContext) throws Exception;

    void storeParallelismOverrides(Context jobContext, Map<String, String> parallelismOverrides)
            throws Exception;

    Optional<Map<String, String>> getParallelismOverrides(Context jobContext) throws Exception;

    void removeParallelismOverrides(Context jobContext) throws Exception;

    /**
     * Flushing is needed because we just save data in cache for all store methods. For less write
     * operations, we flush the cached data to the physical storage only after all operations have
     * been performed.
     */
    void flush(Context jobContext) throws Exception;

    /** Clean up all information related to the current job. */
    void removeInfoFromCache(KEY jobKey);
}


4. Proposed Changes

4.1 Ensure new autoscaler module keeps the generic auto scaling strategy.

It includes JobAutoScalerImpl , ScalingMetricCollector , AutoScalerInfo, ScalingExecutor  etc.
kubernetes related dependencies should be removed from these classes and use JobAutoScalerContext , ScalingRealizer , AutoScalerEventHandler  and AutoScalerStateStore  instead.

Using the RestClusterClient  instead of org.apache.flink.kubernetes.operator.service.FlinkService 

  • The FlinkService is related to kubernetes, so we shouldn't use it.The RestClusterClient is generic flink client, it supports all flink types, including: kubernetes, yarn, standalone.
    The RestClusterClient<String> is included in JobAutoScalerContext.


4.2 KubernetesJobAutoScalerContext

Note: some code can be extracted into a AbstractJobAutoScalerContext, such as: jobKey, jobId, configuration, metric group and restClieentSupplier.

These logic should be generic for k8s, yarn and standalone.

Code Block
/** An implementation of JobAutoscalerContext for Kubernetes. */
public class KubernetesJobAutoScalerContext extends JobAutoScalerContext<ResourceID> {

    private final AbstractFlinkResource<?, ?> resource;

    private final KubernetesClient kubernetesClient;

    public KubernetesJobAutoScalerContext(
            @Nullable JobID jobID,
            @Nullable JobStatus jobStatus,

For current code in kubernetes, most of handlers will record event, all of handlers needs the AbstractFlinkResource , it's saved at INFO extraJobInfo  of JobAutoScalerContext .
The AutoScalerHandler  object is shared for all flink jobs, it doesn't have the job information. However, it needs the AbstractFlinkResource of every job, that's why adding the INFO extraJobInfo  to the JobAutoScalerContext . 

Code Block
/** The kubernetes auto scaler event handler. */
public class KubernetesAutoScalerEventHandler<CR extends AbstractFlinkResource<?, ?>>
        implements AutoScalerEventHandler<ResourceID, CR> {

    private static final Logger LOG =
            LoggerFactory.getLogger(KubernetesAutoScalerEventHandler.class);

    private final KubernetesClient kubernetesClient;

    private final EventRecorder eventRecorder;

    public KubernetesAutoScalerEventHandler(
            KubernetesClient kubernetesClient, EventRecorder eventRecorder) {
        this.kubernetesClient = kubernetesClient;
        this.eventRecorder = eventRecorder;
    }

    @Override
    public void handlerScalingFailure(
            JobAutoScalerContext<ResourceID, CR> contextConfiguration configuration,
            FailureReasonMetricGroup failureReasonmetricGroup,
            StringSupplierWithException<RestClusterClient<String>, errorMessage)Exception> {restClientSupplier,
        eventRecorder.triggerEvent(
    AbstractFlinkResource<?,     ?> resource,
       context.getExtraJobInfo(),
     KubernetesClient kubernetesClient) {
         failureReason.isError() ? EventRecorder.Type.Warning : EventRecorder.Type.Normal,
super(
                    failureReason.toString(ResourceID.fromResource(resource),
                errorMessagejobID,
                EventRecorder.Component.Operator);jobStatus,
    }

      @Override
    public void handlerScalingReport(configuration,
            JobAutoScalerContext<ResourceID, CR> context, String scalingReportMessage) {metricGroup,
        eventRecorder.triggerEvent(
        restClientSupplier);
        context.getExtraJobInfo(),
  this.resource = resource;
        this.kubernetesClient = kubernetesClient;
    EventRecorder.Type.Normal,}

    public AbstractFlinkResource<?, ?>          EventRecorder.Reason.ScalingReport,getResource() {
        return resource;
       EventRecorder.Component.Operator,}

    public KubernetesClient getKubernetesClient() {
        return scalingReportMessage,kubernetesClient;
                "ScalingExecutor");
    }}
}


4.3 KubernetesScalingRealizer

Code Block
/** The Kubernetes implementation for applying parallelism overrides. */
public class KubernetesScalingRealizer
        implements ScalingRealizer<ResourceID, KubernetesJobAutoScalerContext> {

    @Override
    public void handlerRecommendedParallelismrealize(
            KubernetesJobAutoScalerContext JobAutoScalerContext<ResourceIDcontext, CR> contextMap<String,
 String> parallelismOverrides) {
         Map<String, String> recommendedParallelism) {}
}

Alternative implementation: Create an AutoScalerEventHandler for the current job each time JobAutoScaler#scale is called, it means we change the AutoScalerEventHandler to a finer granularity. If so, we can:

  • Adding the AutoScalerEventHandler into the JobAutoScalerContext
  • And adding the JobAutoScalerContext  into the AutoScalerEventHandler
  • All hander methods don't need the JobAutoScalerContext, because it has includes the JobAutoScalerContext

Implement the default and kubernetes classes for AutoScalerStateStore

The default AutoScalerStateStore is the HeapedAutoScalerStateStore, it means the state will be lost after autoscaler restart. Of course, we can implement MySQLAutoScalerStateStore to persist the store in the future.

It's pluggable, so any database or state store can be supported. Flink users can implement other AutoScalerStateStore in their scenarios.

For current code or kubernetes job, the state is persisted to ConfigMap. So the KubernetesAutoScalerStateStore needs to fetch ConfigMap before scaling, and persist the ConfigMap after scaling.

context.getResource()
                .getSpec()
                .getFlinkConfiguration()
                .put(
                        PipelineOptions.PARALLELISM_OVERRIDES.key(),
                        ConfigurationUtils.convertValue(parallelismOverrides, String.class));
    }
}


4.4 KubernetesAutoScalerEventHandler

Code Block
/** An event handler which posts events to the Kubernetes events API. */
public class KubernetesAutoScalerEventHandler
        implements AutoScalerEventHandler<ResourceID, KubernetesJobAutoScalerContext> 
Code Block
/** The kubernetes auto scaler state store, it's based on the config map. */
public class KubernetesAutoScalerStateStore implements AutoScalerStateStore {

    private static final Logger LOG = LoggerFactory.getLogger(KubernetesAutoScalerStateStore.class)EventRecorder eventRecorder;

    privatepublic final KubernetesClient kubernetesClient;
KubernetesAutoScalerEventHandler(EventRecorder eventRecorder) {
    private ConfigMap configMap;

  this.eventRecorder = public KubernetesAutoScalerStateStore(KubernetesClient kubernetesClient, ConfigMap configMap) {eventRecorder;
    }

    @Override
    this.kubernetesClientpublic =void kubernetesClient;
handleEvent(
           this.configMap =KubernetesJobAutoScalerContext configMap;context,
    }

    @Override
    publicType Optional<String> get(String key) {
type,
           return Optional.ofNullable(configMap.getData().get(key));
 String reason,
     }

    @Override
   String publicmessage,
 void put(String key, String value) {
      @Nullable  configMap.getData().put(key, value);String messageKey,
    }

    @Override
    public@Nullable void remove(String keyDuration interval) {
        configMap.getData().remove(key);if (interval == null) {
    }

    @Override
    public void flush() {eventRecorder.triggerEvent(
        try {
            configMap = kubernetesClient.resource(configMap).update();context.getResource(),
        } catch (Exception e) {
            LOG.error(EventRecorder.Type.valueOf(type.name()),
                    "Errorreason,
 while updating autoscaler info configmap, invalidating to clear the cache",
          message,
          e);
          EventRecorder.Component.Operator,
  configMap = null;
            throw e;
   messageKey,
     }
    }

    @Override
    public boolean isValid() {
 context.getKubernetesClient());
        } else {
            eventRecorder.triggerEventByInterval(
                    context.getResource(),
         return configMap != null;
    }
}

POC

I have finished the POC for FLIP-334, here is the POC branch. This branch has 3 commits:

  • The first commit: Create the flink-autoscaler module, and move non-kubernetes related autoscaler classes to flink-autoscaler module.
  • The second commit: Add the general interface for autoscaler.
  • The third commit: Remove some test classes of autoscaler due to they depend on k8s, I didn't support the unit test in this POC.(For the final PR, I will do it)
  • The last commit: Decoupling the autosclaer and kubernetes.

The flink-autoscaler module doesn't depend on any kubernetes dependencies in this POC. I have tested, it works well with kubernetes.
You can run the flink-kubernetes-operator locally based on the flink-kubernetes-operator-docs and run the autoscaling example.

BTW, I didn't support yarn in this POC, Samrat Deb  would like to support it after decoupling flink-autoscaler and kubernetes.

Compatibility, Deprecation, and Migration Plan

It must be compatible with current kubernetes operator.

Test Plan

UT & IT & Manually verify that the autoscaler is working as expected.

          EventRecorder.Type.valueOf(type.name()),
                    reason,
                    EventRecorder.Component.Operator,
                    message,
                    messageKey,
                    context.getKubernetesClient(),
                    interval);
        }
    }
}


4.5 KubernetesAutoScalerStateStore

For current code or kubernetes job, the state is persisted to ConfigMap. So the KubernetesAutoScalerStateStore needs to fetch ConfigMap before scaling, and persist the ConfigMap after scaling.

ConfigMapStore is responsible for put/get/remove seralizedStat.

KubernetesAutoScalerStateStore is responsible for serialize state from raw type to String, and deserialize state from String to raw type, it will access state from ConfigMapStore.

5. Standalone AutoScaler

We will implement the StandaloneAutoScaler at this FLIP, it's the generic autoscaler.

5.1 Separate process, JobListFetcher and control loop

The StandaloneAutoScaler can run as a separate process, the StandaloneAutoscalerEntrypoint is the main class of StandaloneAutoScaler.

The StandaloneAutoScaler is not responsible for job management, so there is no job list. In addition to the interfaces mentioned above, we introduced the JobListFetcher interface for StandaloneAutoScaler. The JobListFetcher will provide the job list and the jobContext of all jobs.

Code Block
/** The JobListFetcher will fetch all job list and the jobContext of all jobs. */
public interface JobListFetcher<KEY> {

    List<JobAutoScalerContext<KEY>> fetch(MetricGroup metricGroup);

}

Control loop

StandaloneAutoscalerEntrypoint call the JobListFetcher to fetch job list, and call the JobAutoscaler#scale  for each job peroidically.

We can define the control-loop-interval  option for StandaloneAutoscalerEntrypoint.


Note: The kubernetes-autoscaler doesn't need the StandaloneAutoScaler and JobListFetcher, it has the job management and control loop.

5.2 The implemetation of JobListFetcher

For flink standalone cluster, we can implement the StandaloneJobListFetcher. User provide the flink standalone cluster address, and StandaloneJobListFetcher will fetch job list via flink rest api.

For yarn cluster, we can implement the YarnJobListFetcher. User provide the yarn address, and YarnJobListFetcher will fetch job list via yarn rest api and flink rest api.

5.3 The implemetation of ScalingRealizer, AutoScalerEventHandler and AutoScalerStateStore

  • We will implement the ScalingApiRealizer, it based on the rescale api of FLIP-291.
  • The generic EventHandler based on the logger.
  • The generic StateStore based on the Heap. This means that the state information is stored in memory and can be lost if the autoscaler restarts.
    • We will implement the JdbcAutoscalerStateStore as well.

6. Compatibility, Deprecation, and Migration Plan

It must be compatible with current kubernetes operator.


7. Test Plan

UT & IT & Manually verify that the autoscaler is working as expected.

Ensure 100% functionality and test coverage of Kubernetes implementation.

8. Rejected Alternatives

Rejected a couple of interface designs, the the whole solution is fine.

yarn-autoscaler

For first version of yarn-autoscaler, we just support rescale job via the rescale api, and don't support re-deploy a new yarn application. Following the some reasons:

  • If we wanna support the entire yarn deployment, it means we need to implement the yarn job management in the yarn-autoscaler. 

  • Not only rescale, but also start stop keepalive, etc.

  • We need to maintains the job jar, job information, etc.

These parts are too heavy, so we just support the rescale api in the first version.

Note: Each company have a flink platform to manage their flink jobs that running on yarn. The flink platform has jobName, job address, job jar, etc. And the flink platform has the ability of start stop keepalive, so these platforms are easy to implement the ScalingRealizer in their cases after this FLIP.

...