Skip to content

Commit

Permalink
Merge branch 'distribworks:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-kripakov-m10 authored Dec 15, 2023
2 parents d1d4276 + 4788221 commit f829f54
Show file tree
Hide file tree
Showing 42 changed files with 16,338 additions and 10,043 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21
id: go

- name: Check out code into the Go module directory
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ build
# Generated files
.docusaurus
.cache-loader
.yarn

# Misc
.env.local
Expand Down
5 changes: 0 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ nfpms:
- dst: /var/log/dkron
type: dir

overrides:
rpm:
replacements:
amd64: x86_64

snapshot:
name_template: "{{ .Tag }}-next"

Expand Down
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [3.2.7] - 2023-12-09

### Changes

- Replace dependent class library github.com/struCoder/pidusage with github.com/shirou/gopsutil/v3/process
- pkg import only once https://github.com/distribworks/dkron/pull/1406
- Bump deps
- Use Go 1.21

### Features

- add TLS options for kafka executor plugin https://github.com/distribworks/dkron/pull/1384
- Resource usage from child processes spawned by the task startup process.
- Introduce two new metrics, dkron_job_execution_time_seconds and dkron_job_execution_done_count, for improved monitoring and alerting capabilities.

### Fixes

- cmd.Process.Kill() does not clean up the started process, causing the job to remain running. https://github.com/distribworks/dkron/pull/1385
- The metric dkron_job_mem_usage_kb now exclusively calculates the memory usage of the task startup process, excluding
- Should output.TotalWritten be judged after cmd.Wait() is executed? https://github.com/distribworks/dkron/pull/1319
- The metrics exposed by dkron are only of summary type and cannot cover related analysis for specific jobs. https://github.com/distribworks/dkron/pull/1310

## [3.2.6] - 2023-09-02

### Changes
Expand All @@ -22,11 +44,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

Do not retry job when unknown status [#1335](https://github.com/distribworks/dkron/pull/1335)
- Do not retry job when unknown status [#1335](https://github.com/distribworks/dkron/pull/1335)

### Features

Prometheus metrics for shell executor [#1330](https://github.com/distribworks/dkron/pull/1330)
- Prometheus metrics for shell executor [#1330](https://github.com/distribworks/dkron/pull/1330)

### Changes

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $(LINUX_PKGS):
fury push --as distribworks $@

PACKAGE_NAME := github.com/distribworks/dkron
GOLANG_CROSS_VERSION ?= v1.18.1
GOLANG_CROSS_VERSION ?= v1.21.5

.PHONY: release-dry-run
release-dry-run:
Expand All @@ -22,7 +22,7 @@ release-dry-run:
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate --skip-publish --timeout=1h
--rm-dist --skip-validate --skip-publish --timeout=1h --parallelism=1

.PHONY: release
release:
Expand Down
63 changes: 48 additions & 15 deletions builtin/bins/dkron-executor-http/testdata/badssl.com-client.pem
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Bag Attributes
localKeyID: 77 23 D2 3A C0 2C 87 E2 AD 98 3F 06 68 F2 54 33 B6 05 0E FE
localKeyID: 57 CC 99 3F 7C 3E D2 81 83 06 43 E2 9A 5E 12 06 9F 13 82 D0
subject=/C=US/ST=California/L=San Francisco/O=BadSSL/CN=BadSSL Client Certificate
issuer=/C=US/ST=California/L=San Francisco/O=BadSSL/CN=BadSSL Client Root Certificate Authority
-----BEGIN CERTIFICATE-----
MIIEnTCCAoWgAwIBAgIJAPYAapdmy98xMA0GCSqGSIb3DQEBCwUA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50aCMbMrjnMZ7nlnqKDeHj2mkx1gnatCOfgX8
9DfFp/f6pv+m7iRfA5/AbT8Eu790wFbqAiouS33dDKgscoOb8Ko42nDL0uFEx32x
i3EBCU1l78zAbYnjJi+++PeMlT20Vna/7k6pgY6Z3jnakZc0Gn0yII9FnmUKvPvz
BIY/Wvgj05DTi2EUVdIXIGqGbsyacLvlYwm1jOo0ZFqgtRvWPVXRvjdapSF0JwSo
c3R43HkF7E0NadTdD1E94Z/oeu+IFUzuvkbJv4XeVwOVd0jEs17l54CJeub+d4V0
NSAmCgRqwu90YPn/2vJ3WwuX5kclcDeqy49vm/wuVzy8kLEzF1timqU4hANqP2t3
3u9rMgMyhGhDE3FdjqPQ93Osvol61tZ9HzYFMzPRAyG6tR/7cK2Tc1WNpquciWRi
hnMactgA+c8bINHuwzAIYiTH5e048Oe/D4Khw1uUWlyg8JRxIhpZP3zgJfpmJ9vc
+/h9HyLWD/wY96bYUDM/glYULa/WRA0NsQKgDFLxjFpjX0+liVFfcQZpqp5vjZoE
v0LQmjkz4+9mcbPwbefcACIIxZbVySlMjNADouKhg2fQki/BUPDJJ+M3VXM7lktZ
TqLklz1stoPMOQUXkXD56S7NPVSCBxOOtbSwicaxDGdm0YM0IQJ10uiUVyTLz34M
12EL5WkWcxl2ywUjEFR6qbGDvG0NoAHiUA0+phxNLO6aqUag054G2WwhesLEXm/W
V5HJ5L379YQNgxS4MkNTcGRy3WoRW5QNnfBYtsKWmI+U0Yz8/8zFbzstM0r1IlEo
Fk/lzQcOnLJTFrepqJPNAP3wzuoMO1tGyat//mchLx5XdXmGEBhYBWokvpr71auz
eD8u94U7pllJc0MJYqYzvdi0ohbGU1Gn8t4y9fWw7w3pzzymoamD2ytnojPjFH7y
qsjE34t7ZQrraAcCN3p3fpMo+66xToRDgjMNStsWlybhslAx3oDfAcMWgXWm9oFg
SdE=
-----END ENCRYPTED PRIVATE KEY-----
112 changes: 0 additions & 112 deletions builtin/bins/dkron-executor-shell/shell.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package main

import (
"encoding/base64"
"errors"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/armon/circbuf"
dkplugin "github.com/distribworks/dkron/v3/plugin"
Expand Down Expand Up @@ -53,111 +46,6 @@ func (s *Shell) Execute(args *dktypes.ExecuteRequest, cb dkplugin.StatusHelper)
return resp, nil
}

// ExecuteImpl do execute command
func (s *Shell) ExecuteImpl(args *dktypes.ExecuteRequest, cb dkplugin.StatusHelper) ([]byte, error) {
output, _ := circbuf.NewBuffer(maxBufSize)

shell, err := strconv.ParseBool(args.Config["shell"])
if err != nil {
shell = false
}
command := args.Config["command"]
env := strings.Split(args.Config["env"], ",")
cwd := args.Config["cwd"]

executionInfo := strings.Split(fmt.Sprintf("ENV_JOB_NAME=%s", args.JobName), ",")
env = append(env, executionInfo...)

cmd, err := buildCmd(command, shell, env, cwd)
if err != nil {
return nil, err
}
err = setCmdAttr(cmd, args.Config)
if err != nil {
return nil, err
}
// use same buffer for both channels, for the full return at the end
cmd.Stderr = reportingWriter{buffer: output, cb: cb, isError: true}
cmd.Stdout = reportingWriter{buffer: output, cb: cb}

stdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
}

defer stdin.Close()

payload, err := base64.StdEncoding.DecodeString(args.Config["payload"])
if err != nil {
return nil, err
}

stdin.Write(payload)
stdin.Close()

jobTimeout := args.Config["timeout"]
var jt time.Duration

if jobTimeout != "" {
jt, err = time.ParseDuration(jobTimeout)
if err != nil {
return nil, errors.New("shell: Error parsing job timeout")
}
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}

log.Printf("shell: going to run %s", command)

err = cmd.Start()
if err != nil {
return nil, err
}

var jobTimeoutMessage string
var jobTimedOut bool

if jt != 0 {
slowTimer := time.AfterFunc(jt, func() {
// Kill child process to avoid cmd.Wait()
err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) // note the minus sign
if err != nil {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. SIGKILL returned error. Job may not have been killed", command, jt)
} else {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. Job was killed", command, jt)
}

jobTimedOut = true
})

defer slowTimer.Stop()
}

quit := make(chan int)

go CollectProcessMetrics(args.JobName, cmd.Process.Pid, quit)

err = cmd.Wait()
quit <- cmd.ProcessState.ExitCode()
close(quit) // exit metric refresh goroutine after job is finished

if jobTimedOut {
_, err := output.Write([]byte(jobTimeoutMessage))
if err != nil {
log.Printf("Error writing output on timeout event: %v", err)
}
}

// Warn if buffer is overwritten
if output.TotalWritten() > output.Size() {
log.Printf("shell: Script '%s' generated %d bytes of output, truncated to %d", command, output.TotalWritten(), output.Size())
}

// Always log output
log.Printf("shell: Command output %s", output)

return output.Bytes(), err
}

// Determine the shell invocation based on OS
func buildCmd(command string, useShell bool, env []string, cwd string) (cmd *exec.Cmd, err error) {
var shell, flag string
Expand Down
Loading

0 comments on commit f829f54

Please sign in to comment.