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 feature flag #56

Merged
merged 40 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dc56eca
update go version
AndersonQ Feb 1, 2023
228782c
add feature flag to control protocol
AndersonQ Feb 1, 2023
9faa3f2
wip
AndersonQ Feb 7, 2023
460fc3f
wip
AndersonQ Feb 7, 2023
ce64944
.
AndersonQ Feb 7, 2023
4492e98
Feature flags and Units are a "change"
AndersonQ Feb 8, 2023
698cf1d
using a Trigger to indicate what changed
AndersonQ Feb 9, 2023
40b1fda
update generated code
AndersonQ Feb 9, 2023
9a53e5a
fix tests
AndersonQ Feb 9, 2023
e5d4cbc
don't use prot.Features, send on 1st checkin, adjust tests
AndersonQ Feb 10, 2023
b062645
.
AndersonQ Feb 10, 2023
5635875
always send features
AndersonQ Feb 10, 2023
7c7d74c
use feature change to determine if unit changed
AndersonQ Feb 13, 2023
496759f
always send feature changed trigger
AndersonQ Feb 13, 2023
0a0b3d0
add featuresIdx, triggers is a bitmask
AndersonQ Feb 15, 2023
40b9cd2
WIP: changes as I tested the agent with the fake inut
AndersonQ Feb 16, 2023
24b65f0
mage check
AndersonQ Feb 21, 2023
4c970c2
remove client.syncFeatures
AndersonQ Feb 21, 2023
44c52ae
send features on unit removed and change Trigger.String
AndersonQ Feb 21, 2023
c23dd09
Adjust Trigger String method
AndersonQ Feb 21, 2023
e416270
fix tests
AndersonQ Feb 22, 2023
e31ef9e
add feature flags to UnitChange
AndersonQ Feb 23, 2023
320d333
.
AndersonQ Feb 23, 2023
201094e
add and fix tests, some PR and small changes
AndersonQ Feb 24, 2023
feba3f0
remove stringer usage
AndersonQ Feb 24, 2023
40bdac0
rebase and go mod tidy
AndersonQ Feb 27, 2023
39ca174
fix test
AndersonQ Feb 27, 2023
35b9f3b
tests fixed
AndersonQ Feb 27, 2023
d8975ea
add GoString and don't send nil FeatureFlags
AndersonQ Feb 28, 2023
56d8b4a
.
AndersonQ Mar 1, 2023
acba3c0
making linter happy
AndersonQ Mar 1, 2023
1bb9fcf
Remove stringer setup from magefile
ycombinator Mar 7, 2023
b9b4996
Fixing rebase errors
ycombinator Mar 7, 2023
09474ef
Fixing duplicate mention in comment
ycombinator Mar 7, 2023
ee7eef8
Pass unit features to unit constructor
ycombinator Mar 8, 2023
29534aa
Remove features information from client
ycombinator Mar 8, 2023
02662bf
Remove features from UnitChanged as they are already part of Unit ins…
ycombinator Mar 8, 2023
d7d45d9
Fixing up tests
ycombinator Mar 8, 2023
b70d208
Start UnitChangedType constants' numbering at 1
ycombinator Mar 9, 2023
5cfba1d
Add comments about Trigger values being bitmasks
ycombinator Mar 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions elastic-agent-client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,32 @@ message CheckinAgentInfo {
bool snapshot = 3;
}

// Feature flags configurations.
message Features {
// Source is the original source of the features. All values from the features
// are included here even if other concrete fields are defined for this message.
google.protobuf.Struct source = 1;

FQDNFeature fqdn = 2;
AndersonQ marked this conversation as resolved.
Show resolved Hide resolved
}

// FQDN feature flag indicates to use FQDN for host.name instead of hostname.
message FQDNFeature {
bool enabled = 1;
}

// A set of units and their expected states and configuration.
message CheckinExpected {
// Units is the expected units the component should be running.
repeated UnitExpected units = 1;
// Agent info is provided only on first CheckinExpected response to the component.
CheckinAgentInfo agent_info = 2;

// Features are the expected feature flags configurations.
// Added on Elastic Agent v8.7.1.
Features features = 3;
AndersonQ marked this conversation as resolved.
Show resolved Hide resolved
AndersonQ marked this conversation as resolved.
Show resolved Hide resolved
// Index of the either current features configuration or new the configuration provided.
uint64 features_idx = 4;
}

// Observed status for a unit.
Expand Down Expand Up @@ -344,6 +364,12 @@ message CheckinObserved {
// Version information about the running program. Should always be included on first checkin, and not again unless
// one of the values have changed.
optional CheckinObservedVersionInfo version_info = 3;

// Features are the expected feature flags configurations.
// Added on Elastic Agent v8.7.1.
Features features = 4;
// Index of the either current features configuration or new the configuration provided.
uint64 features_idx = 5;
}

service ElasticAgent {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/elastic/elastic-agent-client/v7

go 1.17
go 1.18

require (
github.com/gofrs/uuid v4.2.0+incompatible
Expand Down
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,30 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -114,27 +106,19 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
33 changes: 29 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package main

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -67,14 +68,38 @@ func (Update) Prepare() error {
return GoInstall(goProtocGenGoGRPC)
}

// Generate generates the GRPC code.
// Generate generates the necessary GRPC and Go code. It generates both,
// then reports all errors if any.
func (Update) Generate() error {
defer mg.SerialDeps(Format.All)
return sh.RunV(

errGRPC := sh.RunV(
"protoc",
"--go_out=pkg/proto", "--go_opt=paths=source_relative",
"--go-grpc_out=pkg/proto", "--go-grpc_opt=paths=source_relative",
"--go_out=pkg/proto",
"--go_opt=paths=source_relative",
"--go-grpc_out=pkg/proto",
"--go-grpc_opt=paths=source_relative",
"elastic-agent-client.proto")
if errGRPC != nil {
errGRPC = fmt.Errorf("failed to generate GRPC code: %w")
}

errGenerate := sh.RunV("go", "generate", "./...")
if errGenerate != nil {
errGenerate = fmt.Errorf("failed to run go generate: %w")
}

switch {
case errGRPC != nil && errGenerate != nil:
return fmt.Errorf("all code generation failed: '%v' and '%v'",
errGRPC, errGenerate)
case errGRPC != nil:
return errGRPC
case errGenerate != nil:
return errGenerate
}

return nil
}

// All runs update:prepare then update:generate.
Expand Down
6 changes: 4 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,16 @@ func (c *StubClientImpl) OnError(err error) {
}

func waitFor(check func() error) error {
timeout := 5 * time.Minute
started := time.Now()
for {
err := check()
if err == nil {
return nil
}
if time.Now().Sub(started) >= 5*time.Second {
return fmt.Errorf("check timed out after 1 second: %s", err)
if time.Now().Sub(started) >= timeout {
return fmt.Errorf("check timed out after %s: %s",
timeout, err)
}
time.Sleep(10 * time.Millisecond)
}
Expand Down