Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update command-manager to sort documents by delivery timeout #169

Merged
merged 5 commits into from
Dec 9, 2024

Conversation

QU3B1M
Copy link
Member

@QU3B1M QU3B1M commented Dec 5, 2024

Description

Sort documents by delivery_timestamp ascending using default OpenSearch query sorting options.

Internally it converts the timestamp to Unix timestamp and orders from lower to higher.

Working evidence

Using a log.info I've captured the commands and validated the order is correct

{
    "_index": ".commands",
    "_id": "n_eRl5MB624UXaO3F_Bf",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:48Z",
        "delivery_timestamp": "2024-12-05T16:05:18Z"
    },
    "sort": [
        1733414718000
    ]
},
{
    "_index": ".commands",
    "_id": "q_eRl5MB624UXaO3NfCO",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:56Z",
        "delivery_timestamp": "2024-12-05T16:05:20Z"
    },
    "sort": [
        1733414720000
    ]
},
{
    "_index": ".commands",
    "_id": "uveRl5MB624UXaO3RPAx",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:05:00Z",
        "delivery_timestamp": "2024-12-05T16:05:28Z"
    },
    "sort": [
        1733414728000
    ]
},
{
    "_index": ".commands",
    "_id": "vfeRl5MB624UXaO3RPAx",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:05:00Z",
        "delivery_timestamp": "2024-12-05T16:05:35Z"
    },
    "sort": [
        1733414735000
    ]
},
{
    "_index": ".commands",
    "_id": "u_eRl5MB624UXaO3RPAx",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:05:00Z",
        "delivery_timestamp": "2024-12-05T16:05:42Z"
    },
    "sort": [
        1733414742000
    ]
},
{
    "_index": ".commands",
    "_id": "qveRl5MB624UXaO3NfCO",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:56Z",
        "delivery_timestamp": "2024-12-05T16:05:43Z"
    },
    "sort": [
        1733414743000
    ]
},
{
    "_index": ".commands",
    "_id": "ufeRl5MB624UXaO3RPAx",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:05:00Z",
        "delivery_timestamp": "2024-12-05T16:05:54Z"
    },
    "sort": [
        1733414754000
    ]
},
{
    "_index": ".commands",
    "_id": "rPeRl5MB624UXaO3NfCO",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:56Z",
        "delivery_timestamp": "2024-12-05T16:06:01Z"
    },
    "sort": [
        1733414761000
    ]
},
{
    "_index": ".commands",
    "_id": "vPeRl5MB624UXaO3RPAx",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:05:00Z",
        "delivery_timestamp": "2024-12-05T16:06:07Z"
    },
    "sort": [
        1733414767000
    ]
},
{
    "_index": ".commands",
    "_id": "rfeRl5MB624UXaO3NfCO",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:56Z",
        "delivery_timestamp": "2024-12-05T16:06:09Z"
    },
    "sort": [
        1733414769000
    ]
},
{
    "_index": ".commands",
    "_id": "rveRl5MB624UXaO3NfCO",
    "_score": null,
    "_source": {
        ...
        "@timestamp": "2024-12-05T16:04:56Z",
        "delivery_timestamp": "2024-12-05T16:06:26Z"
    },
    "sort": [
        1733414786000
    ]
}
Orders payload captured
{
    "orders": [
        {
            "action": {
                "args": [
                    "/path/to/executable/arg6",
                    "/path/to/executable/arg6",
                    "/path/to/executable/arg6",
                    "/path/to/executable/arg6",
                    "/path/to/executable/arg6"
                ],
                "name": "restart",
                "version": "v4"
            },
            "source": "Engine",
            "document_id": "n_eRl5MB624UXaO3F_Bf",
            "user": "user53",
            "order_id": "m_eRl5MB624UXaO3F_Bc",
            "request_id": "mveRl5MB624UXaO3F_Bc",
            "timeout": 30,
            "target": {
                "id": "target4",
                "type": "agent"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg2"
                ],
                "name": "update",
                "version": "v5"
            },
            "source": "Users/Services",
            "document_id": "q_eRl5MB624UXaO3NfCO",
            "user": "user74",
            "order_id": "o_eRl5MB624UXaO3NfCN",
            "request_id": "oveRl5MB624UXaO3NfCN",
            "timeout": 24,
            "target": {
                "id": "target3",
                "type": "server"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg6"
                ],
                "name": "apply_policy",
                "version": "v5"
            },
            "source": "Engine",
            "document_id": "uveRl5MB624UXaO3RPAx",
            "user": "user52",
            "order_id": "sveRl5MB624UXaO3RPAx",
            "request_id": "sfeRl5MB624UXaO3RPAx",
            "timeout": 28,
            "target": {
                "id": "target7",
                "type": "server"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg10"
                ],
                "name": "update",
                "version": "v5"
            },
            "source": "Users/Services",
            "document_id": "vfeRl5MB624UXaO3RPAx",
            "user": "user74",
            "order_id": "uPeRl5MB624UXaO3RPAx",
            "request_id": "t_eRl5MB624UXaO3RPAx",
            "timeout": 35,
            "target": {
                "id": "target4",
                "type": "agent"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg6"
                ],
                "name": "restart",
                "version": "v3"
            },
            "source": "Users/Services",
            "document_id": "u_eRl5MB624UXaO3RPAx",
            "user": "user99",
            "order_id": "tPeRl5MB624UXaO3RPAx",
            "request_id": "s_eRl5MB624UXaO3RPAx",
            "timeout": 42,
            "target": {
                "id": "target1",
                "type": "agent"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg7"
                ],
                "name": "restart",
                "version": "v5"
            },
            "source": "Users/Services",
            "document_id": "qveRl5MB624UXaO3NfCO",
            "user": "user99",
            "order_id": "ofeRl5MB624UXaO3NfCN",
            "request_id": "oPeRl5MB624UXaO3NfCN",
            "timeout": 47,
            "target": {
                "id": "target5",
                "type": "group"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg8"
                ],
                "name": "restart",
                "version": "v1"
            },
            "source": "Users/Services",
            "document_id": "ufeRl5MB624UXaO3RPAx",
            "user": "user90",
            "order_id": "sPeRl5MB624UXaO3RPAx",
            "request_id": "r_eRl5MB624UXaO3RPAx",
            "timeout": 54,
            "target": {
                "id": "target5",
                "type": "agent"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg2"
                ],
                "name": "update",
                "version": "v1"
            },
            "source": "Users/Services",
            "document_id": "rPeRl5MB624UXaO3NfCO",
            "user": "user68",
            "order_id": "pfeRl5MB624UXaO3NfCN",
            "request_id": "pPeRl5MB624UXaO3NfCN",
            "timeout": 65,
            "target": {
                "id": "target8",
                "type": "server"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg6"
                ],
                "name": "apply_policy",
                "version": "v2"
            },
            "source": "Content manager",
            "document_id": "vPeRl5MB624UXaO3RPAx",
            "user": "user73",
            "order_id": "tveRl5MB624UXaO3RPAx",
            "request_id": "tfeRl5MB624UXaO3RPAx",
            "timeout": 67,
            "target": {
                "id": "target4",
                "type": "group"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg6"
                ],
                "name": "apply_policy",
                "version": "v5"
            },
            "source": "Users/Services",
            "document_id": "rfeRl5MB624UXaO3NfCO",
            "user": "user55",
            "order_id": "p_eRl5MB624UXaO3NfCO",
            "request_id": "pveRl5MB624UXaO3NfCN",
            "timeout": 73,
            "target": {
                "id": "target2",
                "type": "agent"
            },
            "status": "PENDING"
        },
        {
            "action": {
                "args": [
                    "/path/to/executable/arg2"
                ],
                "name": "change_group",
                "version": "v5"
            },
            "source": "Content manager",
            "document_id": "rveRl5MB624UXaO3NfCO",
            "user": "user34",
            "order_id": "qfeRl5MB624UXaO3NfCO",
            "request_id": "qPeRl5MB624UXaO3NfCO",
            "timeout": 90,
            "target": {
                "id": "target7",
                "type": "agent"
            },
            "status": "PENDING"
        }
    ]
}

Issues Resolved

Closes #155

@QU3B1M QU3B1M self-assigned this Dec 5, 2024
@QU3B1M QU3B1M marked this pull request as ready for review December 5, 2024 16:41
@QU3B1M QU3B1M requested a review from a team as a code owner December 5, 2024 16:41
Copy link
Member

@f-galland f-galland left a comment

Choose a reason for hiding this comment

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

Tested and working

@f-galland f-galland merged commit 419369b into master Dec 9, 2024
1 check passed
@f-galland f-galland deleted the enhancement/155-sort-commands-by-delivery-time branch December 9, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort commands by its delivery timeout
2 participants