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

amtool --duration implementation wrong #2740

Closed
ulikl opened this issue Oct 15, 2021 · 1 comment · Fixed by #2741
Closed

amtool --duration implementation wrong #2740

ulikl opened this issue Oct 15, 2021 · 1 comment · Fixed by #2741

Comments

@ulikl
Copy link

ulikl commented Oct 15, 2021

What did you do?

I want to create a silence for 2h in the future via

amtool silence add --start=2021-10-31T10:00:00.000-02:00 --duration=2h ...

What did you expect to see?

According to amtool --help-long the

--duration=DURATION  Duration of silence

I expected a silence starting at 2021-10-31T12:00:00.000Z and ending at 2021-10-31T14:00:00.000Z

Remark: In the Alertmanager GUI the endtime is already calculated from the duration in the browser.
Endtime is here mandatory for submit action. So here we do not face this problem. I haven't check the alertmanager API.

What did you see instead? Under which circumstances?

Abort with error
amtool: error: silence cannot start after it ends

When execution + duration > start timestamp, a silence is created ending at 20d from now.

Environment

  • System information:

    insert output of uname -srm here

Alertmanager:
Linux 3.10.0-1127.19.1.el7.x86_64 x86_64
amtool:

Linux 4.18.0-338.el8.x86_64 x86_64
  • Alertmanager version:

Alertmanager from status GUI:

Branch: HEAD
BuildDate: 20210602-07:50:37
BuildUser: root@b595c7f32520
GoVersion: go1.16.4
Revision: 44f8adc06af5101ad64bd8b9c8b18273f2922051
Version: 0.22.2
 amtool --version
amtool, version 0.22.2 (branch: HEAD, revision: 44f8adc06af5101ad64bd8b9c8b18273f2922051)
  build user:       root@b595c7f32520
  build date:       20210602-07:50:37
  go version:       go1.16.4
  platform:         linux/amd64
  • Prometheus version:

not relevant

  • Alertmanager configuration file:

not relevant

  • Prometheus configuration file:

not relevant

  • Logs:
    no log entries created for these amtool calls.
@nekketsuuu
Copy link
Contributor

This issue is dup of #2490.

I think we can say this is a bug of amtool. If we pass --duration to amtool silence add, it calculates endsAt not as startsAt + duration, but as time.Now() + duration.

endsAt = time.Now().UTC().Add(time.Duration(d))

When the --duration option was impelmented, amtool silence update was implemented to calculate endsAt as startsAt + duration (ref), but amtool silence add was not.

I'll send a patch to change this behavior.

I haven't check the alertmanager API.

Alertmanager API v2 does not prepare the duration option.

properties:
matchers:
$ref: '#/definitions/matchers'
startsAt:
type: string
format: date-time
endsAt:
type: string
format: date-time
createdBy:
type: string
comment:
type: string

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 a pull request may close this issue.

2 participants