Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Conversation

@Megafredo
Copy link
Member

@Megafredo Megafredo commented Jul 10, 2024

Proposed changes

  • Adding query "read" connector
  • Update query "ping" connector
  • Setting up a scheduler and process in helper
  • New variable environment "queue_threshold", default = 500 Mo
  • New variable environment "duration_period"

Related issues

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@Megafredo Megafredo added feature use for describing a new feature to develop filigran team use to identify PR from the Filigran team do not merge Do not merge this PR until this tag will be removed labels Jul 10, 2024
@Megafredo Megafredo self-assigned this Jul 10, 2024
@aHenryJard aHenryJard added the multi-repository When a PR requires several repository changes label Jul 10, 2024
@aHenryJard aHenryJard self-assigned this Jul 10, 2024
try:
# Calculates the duration period in seconds
timedelta_adapter = TypeAdapter(datetime.timedelta)
td = timedelta_adapter.validate_python(duration_period)
Copy link
Member

Choose a reason for hiding this comment

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

Changing the duration_period from "PT5S" to "0" raised an error

  duration_period: '0'

image

Doing this works

Suggested change
td = timedelta_adapter.validate_python(duration_period)
td = timedelta_adapter.validate_python(int(duration_period))

BUT if we doing this, cannot handle the value in ISO8601 format anymore:

image

But the value of duration_period in int works if it's 0

  duration_period: 0

Let's talk about it :)

@Megafredo Megafredo force-pushed the opencti/issue/6325 branch from baebf63 to 57d304a Compare July 12, 2024 07:04
@helene-nguyen
Copy link
Member

Tested locally and everything seems good to me, here are different cases I've tested:

  • For duration_period time in ISO8601 format:
    • Case "0" in string, considered as run_and_terminate process => works
    • Case "PT0S" in string, considered as run_and_terminate process => works
    • Case 0 in int, considered as run_and_terminate process => works
    • Case "P0S" (deliberate mistake), an error is raised because it is not the good format
    • Case "PT3S" (for a scheduled period time of 3 seconds) =>everything works as expected

Steps to Reproduce and my understanding:

  1. Stop the Worker:

    • Begin by stopping the worker process.
  2. Run the Connector:

    • Start the connector process.
  3. Scheduler Checks duration_period Configuration:

    • The scheduler will review the duration_period setting.
  4. Main Process Execution:

    • The main process of the connector will start.
    • We must wait for this process to complete before entering the scheduler configuration and initialization.
  5. Scheduler Activation:

    • The scheduler activates once the specified period time is reached.
  6. Queue Size Threshold Check:

    • The scheduler checks the queue size threshold, defined as queue_threshold.
    • If no environment variable is set, the default threshold is 500MB.
  7. Queue Size Condition:

    • If the connector's queue size exceeds the queue threshold, the message callback process (connector's main process) will pause.
    • The process will not resume until the queue is ingested and reduced sufficiently, allowing it to restart during the next scheduler check.

During the test, the connector was modified to run the scheduler as following:

    def process_message(self):
        """Main process of the connector."""
        [...]

    def run(self):
        self.helper.schedule_iso(
            message_callback=self.process_message,
            duration_period=self.config.duration_period,
        )

duration_timedelta = datetime.timedelta(seconds=duration_period_in_seconds)
next_datetime = datetime.datetime.now() + duration_timedelta
# Set next_run_datetime
self.connector_info.next_run_datetime = next_datetime.strftime(
Copy link
Member

Choose a reason for hiding this comment

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

Could we add information as log about the next run here ?

"""
self.api.app_logger.info("[INFO] Getting connector details ...")
query = """
query GetConnectors($id: String!) {
Copy link
Member

Choose a reason for hiding this comment

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

minor comment: since we get only one connector, I suggest to rename the query name to GetConnector without the s. Or just Connector

@Megafredo Megafredo force-pushed the opencti/issue/6325 branch from ad9ca6a to 96077b6 Compare August 2, 2024 06:11
requirements.txt Outdated
python-magic-bin~=0.4.14; sys_platform == 'win32'
python_json_logger~=2.0.4
PyYAML~=6.0
pydantic~=2.7.4
Copy link
Member

Choose a reason for hiding this comment

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

this dependency seem to break connectors that use older versions of pydantic (1.10.17)

@Megafredo Megafredo merged commit 8ef3069 into master Aug 5, 2024
@Megafredo Megafredo deleted the opencti/issue/6325 branch August 5, 2024 06:11
@helene-nguyen helene-nguyen removed the do not merge Do not merge this PR until this tag will be removed label Sep 17, 2024
aHenryJard pushed a commit to OpenCTI-Platform/opencti that referenced this pull request Nov 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature use for describing a new feature to develop filigran team use to identify PR from the Filigran team multi-repository When a PR requires several repository changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants