Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Add unmanaged mode#103

Merged
rdner merged 11 commits intoelastic:mainfrom
rdner:unmanaged-mode
Sep 22, 2022
Merged

Add unmanaged mode#103
rdner merged 11 commits intoelastic:mainfrom
rdner:unmanaged-mode

Conversation

@rdner
Copy link
Copy Markdown
Member

@rdner rdner commented Sep 1, 2022

What does this PR do?

Add unmanaged/standalone mode.

Why is it important?

So the shipper can be run using a local config file instead of the
control protocol.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] I have made corresponding changes to the documentation
    - [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
    - [ ] I have added an entry in CHANGELOG.md or CHANGELOG-developer.md.

How to test this PR locally

I ran the latest filebeat (73999a009ec97eca7451760730abe7366d8d8156) with the following config:

./filebeat run -d -v -c ~/filebeat_shipper.yml

filebeat_shipper.yml

logging:
  level: debug
  to_stderr: true

filebeat.inputs:
  - type: log
    paths:
      - "/some/path/to/input.log"

processors:
  - add_fields:
      target: "@metadata"
      fields:
        input_id: filebeat_id
        stream_id: input.log
  - add_fields:
      target: "data_stream"
      fields:
        type: file
        namespace: generic
        dataset: some

output.shipper:
  server: "localhost:50052"

input.log

first
second
third
fourth
fifth

And I ran shipper with the following config:

./elastic-agent-shipper run -c elastic-agent-shipper.yml

elastic-agent-shipper.yml

server:
  strict_mode: false
  port: 50052
  tls: false

logging:
  level: debug
  selectors: ["*"]
  to_stderr: true

monitoring:
  enabled: true
  interval: 5s
  log: true
  http:
    enabled: true
    host: "localhost"
    port: 8282
    name: "queue"

I got the following logs from filebeat:

{"log.level":"info","@timestamp":"2022-09-06T15:13:55.420+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":144},"message":"Starting metrics logging every 30s","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.420+0200","log.origin":{"file.name":"instance/beat.go","file.line":470},"message":"filebeat start running.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.458+0200","log.origin":{"file.name":"memlog/store.go","file.line":134},"message":"Finished loading transaction log file for '/Users/rdner/Projects/beats/filebeat/data/registry/filebeat'. Active transaction id=5958","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"warn","@timestamp":"2022-09-06T15:13:55.458+0200","log.origin":{"file.name":"beater/filebeat.go","file.line":279},"message":"Filebeat is unable to load the ingest pipelines for the configured modules because the Elasticsearch output is not configured/enabled. If you have already loaded the ingest pipelines or are using Logstash pipelines, you can ignore this warning.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.458+0200","log.logger":"registrar","log.origin":{"file.name":"registrar/registrar.go","file.line":109},"message":"States Loaded from registrar: 3","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.458+0200","log.logger":"crawler","log.origin":{"file.name":"beater/crawler.go","file.line":71},"message":"Loading Inputs: 1","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.458+0200","log.logger":"crawler","log.origin":{"file.name":"beater/crawler.go","file.line":117},"message":"starting input, keys present on the config: [filebeat.inputs.0.paths.0 filebeat.inputs.0.type]","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"warn","@timestamp":"2022-09-06T15:13:55.458+0200","log.logger":"cfgwarn","log.origin":{"file.name":"log/input.go","file.line":90},"message":"DEPRECATED: Log input. Use Filestream input instead.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.459+0200","log.logger":"input","log.origin":{"file.name":"log/input.go","file.line":172},"message":"Configured paths: [/Users/rdner/Projects/tests/input.log]","service.name":"filebeat","input_id":"0c0f53a5-c279-461d-888a-215c8e29d350","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.459+0200","log.logger":"crawler","log.origin":{"file.name":"beater/crawler.go","file.line":148},"message":"Starting input (ID: 4409840144785466051)","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.459+0200","log.logger":"crawler","log.origin":{"file.name":"beater/crawler.go","file.line":106},"message":"Loading and starting Inputs completed. Enabled inputs: 1","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.459+0200","log.logger":"input.harvester","log.origin":{"file.name":"log/harvester.go","file.line":310},"message":"Harvester started for paths: [/Users/rdner/Projects/tests/input.log]","service.name":"filebeat","input_id":"0c0f53a5-c279-461d-888a-215c8e29d350","source_file":"/Users/rdner/Projects/tests/input.log","state_id":"native::82114290-16777234","finished":false,"os_id":"82114290-16777234","harvester_id":"93fb9f08-3e33-4d65-8779-c7456c313e6b","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:56.460+0200","log.logger":"publisher_pipeline_output","log.origin":{"file.name":"pipeline/client_worker.go","file.line":139},"message":"Connecting to backoff(shipper)","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:56.466+0200","log.logger":"publisher_pipeline_output","log.origin":{"file.name":"pipeline/client_worker.go","file.line":147},"message":"Connection to backoff(shipper) established","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2022-09-06T15:14:08.834+0200","log.logger":"shipper","log.origin":{"file.name":"shipper/shipper.go","file.line":170},"message":"acknowledgment loop stopped: acknowledgment failed due to the connectivity error: rpc error: code = Canceled desc = server is stopped: context canceled","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:14:25.422+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":0},"total":{"ticks":1,"time":{"ms":1},"value":1},"user":{"ticks":1,"time":{"ms":1}}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","name":"filebeat","uptime":{"ms":30016},"version":"8.5.0"},"memstats":{"gc_next":8047120,"memory_alloc":5075672,"memory_sys":26084360,"memory_total":27079680,"rss":46514176},"runtime":{"goroutines":25}},"filebeat":{"events":{"added":8,"done":8},"harvester":{"open_files":1,"running":1,"started":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"acked":5,"active":0,"batches":1,"total":5},"type":"shipper"},"pipeline":{"clients":1,"events":{"active":0,"filtered":3,"published":5,"retry":5,"total":8},"queue":{"acked":5,"max_events":4096}}},"registrar":{"states":{"cleanup":1,"current":3,"update":8},"writes":{"success":2,"total":2}},"system":{"cpu":{"cores":10},"load":{"1":1.7754,"15":2.895,"5":2.5586,"norm":{"1":0.1775,"15":0.2895,"5":0.2559}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:14:55.426+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":0},"total":{"ticks":2,"time":{"ms":1},"value":2},"user":{"ticks":2,"time":{"ms":1}}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","uptime":{"ms":60016},"version":"8.5.0"},"memstats":{"gc_next":8047120,"memory_alloc":7261048,"memory_total":29265056,"rss":46546944},"runtime":{"goroutines":25}},"filebeat":{"harvester":{"open_files":1,"running":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"active":0}},"pipeline":{"clients":1,"events":{"active":0}}},"registrar":{"states":{"current":3}},"system":{"load":{"1":2.0688,"15":2.8862,"5":2.5645,"norm":{"1":0.2069,"15":0.2886,"5":0.2564}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:15:25.427+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":0},"total":{"ticks":2,"value":2},"user":{"ticks":2}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","uptime":{"ms":90017},"version":"8.5.0"},"memstats":{"gc_next":12910592,"memory_alloc":6182928,"memory_total":31450736,"rss":46743552},"runtime":{"goroutines":25}},"filebeat":{"harvester":{"open_files":1,"running":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"active":0}},"pipeline":{"clients":1,"events":{"active":0}}},"registrar":{"states":{"current":3}},"system":{"load":{"1":2.146,"15":2.8599,"5":2.5269,"norm":{"1":0.2146,"15":0.286,"5":0.2527}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:15:55.444+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":1,"time":{"ms":1}},"total":{"ticks":3,"time":{"ms":1},"value":3},"user":{"ticks":2}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","uptime":{"ms":120017},"version":"8.5.0"},"memstats":{"gc_next":12910592,"memory_alloc":8353672,"memory_total":33621480,"rss":46759936},"runtime":{"goroutines":25}},"filebeat":{"harvester":{"open_files":1,"running":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"active":0}},"pipeline":{"clients":1,"events":{"active":0}}},"registrar":{"states":{"current":3}},"system":{"load":{"1":2.3403,"15":2.8511,"5":2.5386,"norm":{"1":0.234,"15":0.2851,"5":0.2539}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:16:25.448+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":1},"total":{"ticks":3,"value":3},"user":{"ticks":2}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","uptime":{"ms":150019},"version":"8.5.0"},"memstats":{"gc_next":12910592,"memory_alloc":10530736,"memory_sys":4194304,"memory_total":35798544,"rss":46891008},"runtime":{"goroutines":25}},"filebeat":{"harvester":{"open_files":1,"running":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"active":0}},"pipeline":{"clients":1,"events":{"active":0}}},"registrar":{"states":{"current":3}},"system":{"load":{"1":2.7847,"15":2.8613,"5":2.603,"norm":{"1":0.2785,"15":0.2861,"5":0.2603}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:16:55.446+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":186},"message":"Non-zero metrics in the last 30s","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":1},"total":{"ticks":3,"value":3},"user":{"ticks":2}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","uptime":{"ms":180017},"version":"8.5.0"},"memstats":{"gc_next":12852240,"memory_alloc":6150312,"memory_total":37977992,"rss":47022080},"runtime":{"goroutines":25}},"filebeat":{"harvester":{"open_files":1,"running":1}},"libbeat":{"config":{"module":{"running":0}},"output":{"events":{"active":0}},"pipeline":{"clients":1,"events":{"active":0}}},"registrar":{"states":{"current":3}},"system":{"load":{"1":3.2188,"15":2.8936,"5":2.7202,"norm":{"1":0.3219,"15":0.2894,"5":0.272}}}},"ecs.version":"1.6.0"}}
^C{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.origin":{"file.name":"beater/filebeat.go","file.line":423},"message":"Stopping filebeat","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.origin":{"file.name":"beater/crawler.go","file.line":155},"message":"Stopping Crawler","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.origin":{"file.name":"beater/crawler.go","file.line":165},"message":"Stopping 1 inputs","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.logger":"crawler","log.origin":{"file.name":"beater/crawler.go","file.line":170},"message":"Stopping input: 4409840144785466051","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.origin":{"file.name":"input/input.go","file.line":134},"message":"input ticker stopped","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.logger":"input.harvester","log.origin":{"file.name":"log/harvester.go","file.line":337},"message":"Reader was closed. Closing.","service.name":"filebeat","input_id":"0c0f53a5-c279-461d-888a-215c8e29d350","source_file":"/Users/rdner/Projects/tests/input.log","state_id":"native::82114290-16777234","finished":false,"os_id":"82114290-16777234","harvester_id":"93fb9f08-3e33-4d65-8779-c7456c313e6b","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.origin":{"file.name":"beater/crawler.go","file.line":185},"message":"Crawler stopped","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.logger":"registrar","log.origin":{"file.name":"registrar/registrar.go","file.line":132},"message":"Stopping Registrar","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.542+0200","log.logger":"registrar","log.origin":{"file.name":"registrar/registrar.go","file.line":166},"message":"Ending Registrar","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.543+0200","log.logger":"registrar","log.origin":{"file.name":"registrar/registrar.go","file.line":137},"message":"Registrar stopped","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.564+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":194},"message":"Total metrics","service.name":"filebeat","monitoring":{"metrics":{"beat":{"cpu":{"system":{"ticks":1,"time":{"ms":1}},"total":{"ticks":3,"time":{"ms":3},"value":3},"user":{"ticks":2,"time":{"ms":2}}},"info":{"ephemeral_id":"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3","name":"filebeat","uptime":{"ms":201134},"version":"8.5.0"},"memstats":{"gc_next":12852240,"memory_alloc":8342640,"memory_sys":30278664,"memory_total":40170320,"rss":47022080},"runtime":{"goroutines":10}},"filebeat":{"events":{"active":0,"added":8,"done":8},"harvester":{"closed":1,"open_files":0,"running":0,"skipped":0,"started":1},"input":{"log":{"files":{"renamed":0,"truncated":0}}}},"libbeat":{"config":{"module":{"running":0,"starts":0,"stops":0},"reloads":0,"scans":0},"output":{"events":{"acked":5,"active":0,"batches":1,"dropped":0,"duplicates":0,"failed":0,"toomany":0,"total":5},"read":{"bytes":0,"errors":0},"type":"shipper","write":{"bytes":0,"errors":0}},"pipeline":{"clients":0,"events":{"active":0,"dropped":0,"failed":0,"filtered":3,"published":5,"retry":5,"total":8},"queue":{"acked":5,"max_events":4096}}},"registrar":{"states":{"cleanup":1,"current":3,"update":8},"writes":{"fail":0,"success":2,"total":2}},"system":{"cpu":{"cores":10},"load":{"1":3.0811,"15":2.8896,"5":2.7212,"norm":{"1":0.3081,"15":0.289,"5":0.2721}}}},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.564+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":195},"message":"Uptime: 3m21.135659583s","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.564+0200","log.logger":"monitoring","log.origin":{"file.name":"log/log.go","file.line":162},"message":"Stopping metrics logging.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:17:16.564+0200","log.origin":{"file.name":"instance/beat.go","file.line":475},"message":"filebeat stopped.","service.name":"filebeat","ecs.version":"1.6.0"}

and the following logs from the shipper:

{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"log/log.go","file.line":30},"message":"Starting metrics logging...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"expvar/expvars.go","file.line":45},"message":"Starting expvar monitoring on localhost:8282","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"controller/runner.go","file.line":75},"message":"monitoring is ready.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"controller/runner.go","file.line":77},"message":"initializing the output...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"controller/runner.go","file.line":81},"message":"output was initialized.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"controller/runner.go","file.line":83},"message":"initializing the gRPC server...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.750+0200","log.origin":{"file.name":"controller/runner.go","file.line":98},"message":"gRPC server initialized.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:30.753+0200","log.origin":{"file.name":"controller/runner.go","file.line":129},"message":"gRPC server is ready and is listening on localhost:50052","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:35.753+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:40.751+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:45.751+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:50.751+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:13:55.751+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:56.466+0200","log.logger":"shipper-server","log.origin":{"file.name":"server/server.go","file.line":153},"message":"new subscriber for persisted index change","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:56.468+0200","log.logger":"shipper-server","log.origin":{"file.name":"server/server.go","file.line":142},"message":"finished publishing a batch. Events = 5, accepted = 5, accepted index = 4","ecs.version":"1.6.0"}
timestamp:{seconds:1662470035 nanos:459251000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:0}}}}} data:{key:"message" value:{string_value:"first"}}}
timestamp:{seconds:1662470035 nanos:459283000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:6}}}}} data:{key:"message" value:{string_value:"second"}}}
timestamp:{seconds:1662470035 nanos:459292000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:13}}}}} data:{key:"message" value:{string_value:"third"}}}
timestamp:{seconds:1662470035 nanos:459305000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:19}}}}} data:{key:"message" value:{string_value:"fourth"}}}
timestamp:{seconds:1662470035 nanos:459312000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:26}}}}} data:{key:"message" value:{string_value:"fifth"}}}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:57.471+0200","log.origin":{"file.name":"memqueue/ackloop.go","file.line":81},"message":"ackloop: return ack to broker loop:5","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:13:57.471+0200","log.origin":{"file.name":"memqueue/ackloop.go","file.line":83},"message":"ackloop:  done send ack","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:14:00.751+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:14:05.750+0200","log.origin":{"file.name":"log/log.go","file.line":40},"message":"Queue Statistics","queue":{"current_level":0,"is_full":false,"limit_reached_count":0,"max_level":4096,"oldest_active_event":"0001-01-01T00:00:00.000Z","unacked_read":0},"ecs.version":"1.6.0"}
^C{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.832+0200","log.origin":{"file.name":"controller/run.go","file.line":53},"message":"Received sigterm/sigint, stopping","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.833+0200","log.origin":{"file.name":"controller/runner.go","file.line":145},"message":"shipper is shutting down...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.833+0200","log.origin":{"file.name":"controller/runner.go","file.line":151},"message":"shipper is stopped.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.833+0200","log.origin":{"file.name":"controller/runner.go","file.line":154},"message":"gRPC server is shutting down...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.833+0200","log.logger":"shipper-server","log.origin":{"file.name":"server/server.go","file.line":183},"message":"unsubscribed from persisted index change","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.834+0200","log.origin":{"file.name":"controller/runner.go","file.line":157},"message":"gRPC server is stopped, all connections closed.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.835+0200","log.origin":{"file.name":"controller/runner.go","file.line":160},"message":"monitoring is shutting down...","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2022-09-06T15:14:08.835+0200","log.origin":{"file.name":"monitoring/queuemon.go","file.line":106},"message":"Shutting down metrics monitor...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.835+0200","log.origin":{"file.name":"expvar/expvars.go","file.line":84},"message":"Closing expvar server...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.837+0200","log.origin":{"file.name":"controller/runner.go","file.line":163},"message":"monitoring is stopped.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.837+0200","log.origin":{"file.name":"controller/runner.go","file.line":166},"message":"queue is shutting down...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.837+0200","log.origin":{"file.name":"controller/runner.go","file.line":172},"message":"queue is stopped.","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.837+0200","log.origin":{"file.name":"controller/runner.go","file.line":178},"message":"waiting for pending events in the output...","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2022-09-06T15:14:08.837+0200","log.origin":{"file.name":"controller/runner.go","file.line":181},"message":"all pending events are flushed","ecs.version":"1.6.0"}

These messages indicate that filebeat successfully published a batch of events:

filebeat

{
  "log.level": "info",
  "@timestamp": "2022-09-06T15:14:25.422+0200",
  "log.logger": "monitoring",
  "log.origin": {
    "file.name": "log/log.go",
    "file.line": 186
  },
  "message": "Non-zero metrics in the last 30s",
  "service.name": "filebeat",
  "monitoring": {
    "metrics": {
      "beat": {
        "cpu": {
          "system": {
            "ticks": 0
          },
          "total": {
            "ticks": 1,
            "time": {
              "ms": 1
            },
            "value": 1
          },
          "user": {
            "ticks": 1,
            "time": {
              "ms": 1
            }
          }
        },
        "info": {
          "ephemeral_id": "1dacd9f3-4375-4b82-ac46-4f4e3be67fd3",
          "name": "filebeat",
          "uptime": {
            "ms": 30016
          },
          "version": "8.5.0"
        },
        "memstats": {
          "gc_next": 8047120,
          "memory_alloc": 5075672,
          "memory_sys": 26084360,
          "memory_total": 27079680,
          "rss": 46514176
        },
        "runtime": {
          "goroutines": 25
        }
      },
      "filebeat": {
        "events": {
          "added": 8,
          "done": 8
        },
        "harvester": {
          "open_files": 1,
          "running": 1,
          "started": 1
        }
      },
      "libbeat": {
        "config": {
          "module": {
            "running": 0
          }
        },
        "output": {
          "events": {
            "acked": 5,
            "active": 0,
            "batches": 1,
            "total": 5
          },
          "type": "shipper"
        },
        "pipeline": {
          "clients": 1,
          "events": {
            "active": 0,
            "filtered": 3,
            "published": 5,
            "retry": 5,
            "total": 8
          },
          "queue": {
            "acked": 5,
            "max_events": 4096
          }
        }
      },
      "registrar": {
        "states": {
          "cleanup": 1,
          "current": 3,
          "update": 8
        },
        "writes": {
          "success": 2,
          "total": 2
        }
      },
      "system": {
        "cpu": {
          "cores": 10
        },
        "load": {
          "1": 1.7754,
          "15": 2.895,
          "5": 2.5586,
          "norm": {
            "1": 0.1775,
            "15": 0.2895,
            "5": 0.2559
          }
        }
      }
    },
    "ecs.version": "1.6.0"
  }
}

shipper

{
  "log.level": "debug",
  "@timestamp": "2022-09-06T15:13:56.468+0200",
  "log.logger": "shipper-server",
  "log.origin": {
    "file.name": "server/server.go",
    "file.line": 142
  },
  "message": "finished publishing a batch. Events = 5, accepted = 5, accepted index = 4",
  "ecs.version": "1.6.0"
}

and

timestamp:{seconds:1662470035 nanos:459251000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:0}}}}} data:{key:"message" value:{string_value:"first"}}}
timestamp:{seconds:1662470035 nanos:459283000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:6}}}}} data:{key:"message" value:{string_value:"second"}}}
timestamp:{seconds:1662470035 nanos:459292000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:13}}}}} data:{key:"message" value:{string_value:"third"}}}
timestamp:{seconds:1662470035 nanos:459305000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:19}}}}} data:{key:"message" value:{string_value:"fourth"}}}
timestamp:{seconds:1662470035 nanos:459312000} source:{input_id:"filebeat_id" stream_id:"input.log"} data_stream:{type:"file" dataset:"some" namespace:"generic"} metadata:{data:{key:"input_id" value:{string_value:"filebeat_id"}} data:{key:"stream_id" value:{string_value:"input.log"}}} fields:{data:{key:"agent" value:{struct_value:{data:{key:"ephemeral_id" value:{string_value:"1dacd9f3-4375-4b82-ac46-4f4e3be67fd3"}} data:{key:"id" value:{string_value:"4fd6b173-0f13-4792-888a-b54dcd85496c"}} data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}} data:{key:"type" value:{string_value:"filebeat"}} data:{key:"version" value:{string_value:"8.5.0"}}}}} data:{key:"data_stream" value:{struct_value:{data:{key:"dataset" value:{string_value:"some"}} data:{key:"namespace" value:{string_value:"generic"}} data:{key:"type" value:{string_value:"file"}}}}} data:{key:"ecs" value:{struct_value:{data:{key:"version" value:{string_value:"8.0.0"}}}}} data:{key:"host" value:{struct_value:{data:{key:"name" value:{string_value:"MacBook-Pro.localdomain"}}}}} data:{key:"input" value:{struct_value:{data:{key:"type" value:{string_value:"log"}}}}} data:{key:"log" value:{struct_value:{data:{key:"file" value:{struct_value:{data:{key:"path" value:{string_value:"/Users/rdner/Projects/tests/input.log"}}}}} data:{key:"offset" value:{number_value:26}}}}} data:{key:"message" value:{string_value:"fifth"}}}

Then I stopped the shipper sending the INTSIG and observed that everything shut down correctly.

Related issues

So the shipper can be run using a local config file instead of the
control protocol.
@rdner rdner added the v8.5.0 label Sep 1, 2022
@rdner rdner self-assigned this Sep 1, 2022
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Sep 1, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-09-22T07:52:19.265+0000

  • Duration: 11 min 38 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@rdner rdner marked this pull request as ready for review September 6, 2022 13:49
@rdner rdner requested a review from a team as a code owner September 6, 2022 13:49
@rdner rdner requested review from cmacknz, faec and leehinman and removed request for a team September 6, 2022 13:49
Copy link
Copy Markdown
Contributor

@fearful-symmetry fearful-symmetry left a comment

Choose a reason for hiding this comment

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

Left a few basic comments, since a lot of the shipper functionality has changed since I last looked at it.

Depending on the scope of this PR, I kind of wonder if it would make more sense to refactor some of the "managed" initialization/shutdown functions so we can import them across both managed and unmanaged code, so we're not duplicating the functionality as much.

if err != nil {
return fmt.Errorf("error reading control config from agent: %w", err)
cfg, err := config.ReadConfigFromFile()
switch {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wonder if there's a more idiomatic way to do this? Beats have a special flag (management.enabled), and I wonder if that's a better fit than trying and reverting to unmanaged on error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But in case you need to test several configurations you also need a configuration filename. I figured it would be easier to just base the managed mode on a single flag.

// Testing that the server is running and only then unlock the mutex.
// Otherwise if `Close` is called at the same time as `Start` it causes race condition.
go func() {
defer r.mu.Unlock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that the only thing this mutex is used for? If so, you might want to rename it, I was a tad confused by the mutex itself.

Alternatively, depending on the where the race is in Close() you could also use a WaitGroup, or just an atomic flag that can tell the Close() what shutdown components to avoid

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason this mutex exists is that the controller tests call Close before Start finishes. Which is theoretically possible with the control protocol, I guess. I'll rename it to startMutex.

defer r.mu.Unlock()
// initialization can fail on each step, so it's possible that the runner
// is partially initialized and we have to account for that.
r.once.Do(func() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this need to be in a once block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, after I added nil checks there is no need anymore, I'll remove it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After a second thought, I think we need it in case there will be several concurrent calls of Close by the control protocol. We don't want a race condition with nil checks, I remember it now.

}
done := make(doneChan)
go func() {
err = runner.Start()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we return this err below, any possibility we get an odd situation where a signal might happen before Start finishes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unless I missed something, this should be okay because of the startMutex that would not allow to execute Close until Start finished.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Sep 14, 2022

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @rdner? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@rdner rdner requested a review from faec September 20, 2022 15:23
@cmacknz
Copy link
Copy Markdown
Member

cmacknz commented Sep 21, 2022

Can we update the README to indicate how to run this: https://github.com/elastic/elastic-agent-shipper/blob/main/README.md?

Copy link
Copy Markdown
Contributor

@faec faec left a comment

Choose a reason for hiding this comment

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

looks good, thanks!

@rdner
Copy link
Copy Markdown
Member Author

rdner commented Sep 22, 2022

@cmacknz done in f5b5acf

@rdner rdner merged commit 24d1fc3 into elastic:main Sep 22, 2022
@rdner rdner deleted the unmanaged-mode branch September 22, 2022 14:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow running the shipper in standalone mode independently of the agent

6 participants