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

Add .scheduled-commands template #173

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

f-galland
Copy link
Member

Description

This PR adds a template for the .scheduled-commands index for the purpose of setting its replicas to 0.

Issues Resolved

Closes #168

@f-galland f-galland self-assigned this Dec 6, 2024
@f-galland
Copy link
Member Author

The template is loaded properly upon startup:

fede@tyner:~
$ curl http://localhost:9200/_template/index-template-scheduled-commands?pretty
{
  "index-template-scheduled-commands" : {
    "order" : 0,
    "index_patterns" : [
      ".scheduled-commands"
    ],
    "settings" : {
      "index" : {
        "refresh_interval" : "5s",
        "hidden" : "true",
        "number_of_shards" : "1",
        "number_of_replicas" : "0"
      }
    },
    "mappings" : {
      "dynamic" : "strict",
      "properties" : {
        "enabled_time" : {
          "format" : "epoch_millis",
          "type" : "date"
        },
        "schedule" : {
          "properties" : {
            "interval" : {
              "properties" : {
                "start_time" : {
                  "format" : "epoch_millis",
                  "type" : "date"
                },
                "period" : {
                  "type" : "integer"
                },
                "unit" : {
                  "type" : "keyword"
                }
              }
            }
          }
        },
        "last_update_time" : {
          "format" : "epoch_millis",
          "type" : "date"
        },
        "name" : {
          "type" : "keyword"
        },
        "enabled" : {
          "type" : "boolean"
        }
      }
    },
    "aliases" : { }
  }
}

Indexing a document with the proper format works:

## scheduled.json contains a sample document

fede@tyner:~
$ cat scheduled.json | jq '.hits.hits[0]._source'
{
  "name": "command_manager_scheduler_extension",
  "enabled": true,
  "schedule": {
    "interval": {
      "start_time": 1733480988301,
      "period": 1,
      "unit": "Minutes"
    }
  },
  "enabled_time": 1733480988302,
  "last_update_time": 1733480988302
}

## Indexing the sample document from above
fede@tyner:~
$ curl -XPOST http://localhost:9200/.scheduled-commands/_doc -H 'Content-Type: application/json' -d $(cat scheduled.json | jq -c '.hits.hits[0]._source')
{"_index":".scheduled-commands","_id":"Hr2em5MBoZTQTWo9JuC1","_version":1,"result":"created","_shards":{"total":1,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

## We get a proper response
fede@tyner:~
$ curl http://localhost:9200/.scheduled-commands/_search?pretty
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : ".scheduled-commands",
        "_id" : "Hr2em5MBoZTQTWo9JuC1",
        "_score" : 1.0,
        "_source" : {
          "name" : "command_manager_scheduler_extension",
          "enabled" : true,
          "schedule" : {
            "interval" : {
              "start_time" : 1733480988301,
              "period" : 1,
              "unit" : "Minutes"
            }
          },
          "enabled_time" : 1733480988302,
          "last_update_time" : 1733480988302
        }
      }
    ]
  }
}

@f-galland f-galland marked this pull request as ready for review December 6, 2024 11:00
@f-galland f-galland requested a review from a team as a code owner December 6, 2024 11:00
@QU3B1M
Copy link
Member

QU3B1M commented Dec 6, 2024

The index is being created at plugin startup

curl -k -s "http://127.0.0.1:9200/_cat/indices/.*"
green open .scheduled-commands ovPW-_YlRLmAxW80rSWTKA 1 0 1 0 5.5kb 5.5kb

Template is loaded correctly

curl "http://localhost:9200/_template/index-template-scheduled-commands?pretty"
{
  "index-template-scheduled-commands" : {
    "order" : 0,
    "index_patterns" : [
      ".scheduled-commands"
    ],
    "settings" : {
      "index" : {
        "refresh_interval" : "5s",
        "hidden" : "true",
        "number_of_shards" : "1",
        "number_of_replicas" : "0"
      }
    },
    "mappings" : {
      "dynamic" : "strict",
      "properties" : {
        "enabled_time" : {
          "format" : "epoch_millis",
          "type" : "date"
        },
        "schedule" : {
          "properties" : {
            "interval" : {
              "properties" : {
                "start_time" : {
                  "format" : "epoch_millis",
                  "type" : "date"
                },
                "period" : {
                  "type" : "integer"
                },
                "unit" : {
                  "type" : "keyword"
                }
              }
            }
          }
        },
        "last_update_time" : {
          "format" : "epoch_millis",
          "type" : "date"
        },
        "name" : {
          "type" : "keyword"
        },
        "enabled" : {
          "type" : "boolean"
        }
      }
    },
    "aliases" : { }
  }
}

Document indexed

curl "http://localhost:9200/.scheduled-commands/_search?pretty"
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : ".scheduled-commands",
        "_id" : "roMcnJMBlwwGYiisRW4W",
        "_score" : 1.0,
        "_source" : {
          "name" : "command_manager_scheduler_extension",
          "enabled" : true,
          "schedule" : {
            "interval" : {
              "start_time" : 1733490918679,
              "period" : 1,
              "unit" : "Minutes"
            }
          },
          "enabled_time" : 1733490918679,
          "last_update_time" : 1733490918679
        }
      }
    ]
  }
}

Copy link
Member

@QU3B1M QU3B1M left a comment

Choose a reason for hiding this comment

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

LGTM

@f-galland f-galland merged commit ed6d08a into master Dec 6, 2024
1 check passed
@f-galland f-galland deleted the 168-add-scheduled-commands-template branch December 6, 2024 13:23
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.

[BUG] Job Scheduler internal index has replicas
2 participants