Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .bldr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,7 @@ paths = [
"lib/io/*",
"lib/logger/*",
"lib/pgutils/*",
"lib/platform/command/*",
"lib/platform/config/*",
"lib/platform/pg/*",
"lib/platform/sys/*",
"lib/proc/*",
"lib/proxy/*",
"lib/secrets/*",
"lib/simpledatemath/*",
Expand All @@ -1142,7 +1138,6 @@ paths = [
"vendor/github.com/apache/thrift/*",
"vendor/github.com/beorn7/perks/*",
"vendor/github.com/codahale/hdrhistogram/*",
"vendor/github.com/davecgh/go-spew/*",
"vendor/github.com/fsnotify/fsnotify/*",
"vendor/github.com/go-gorp/gorp/*",
"vendor/github.com/gogo/protobuf/*",
Expand All @@ -1165,7 +1160,6 @@ paths = [
"vendor/github.com/pelletier/go-toml/*",
"vendor/github.com/peterbourgon/mergemap/*",
"vendor/github.com/pkg/errors/*",
"vendor/github.com/pmezard/go-difflib/*",
"vendor/github.com/prometheus/client_golang/*",
"vendor/github.com/prometheus/client_model/*",
"vendor/github.com/prometheus/common/*",
Expand All @@ -1177,8 +1171,6 @@ paths = [
"vendor/github.com/spf13/jwalterweatherman/*",
"vendor/github.com/spf13/pflag/*",
"vendor/github.com/spf13/viper/*",
"vendor/github.com/stretchr/objx/*",
"vendor/github.com/stretchr/testify/*",
"vendor/github.com/teambition/rrule-go/*",
"vendor/github.com/uber/jaeger-client-go/*",
"vendor/github.com/uber/jaeger-lib/*",
Expand Down
1 change: 1 addition & 0 deletions api/config/pg_gateway/config_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func DefaultConfigRequest() *ConfigRequest {
c.V1.Sys.Service.Port = w.Int32(10145)

c.V1.Sys.Timeouts.Connect = w.Int32(5)
c.V1.Sys.Timeouts.Idle = w.Int32(43200)
return c
}

Expand Down
79 changes: 44 additions & 35 deletions api/config/pg_gateway/config_request.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/config/pg_gateway/config_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message ConfigRequest {

message Timeouts {
google.protobuf.Int32Value connect = 1;
google.protobuf.Int32Value idle = 2;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"strings"
"time"

_ "github.com/lib/pq"
"github.com/lib/pq"
"github.com/pkg/errors"

"github.com/chef/automate/components/applications-service/pkg/storage"
"github.com/chef/automate/lib/pgutils"
"github.com/chef/automate/lib/platform/pg"
)

// composedService is a more user friendly and clear representation of a service.
Expand Down Expand Up @@ -303,7 +302,7 @@ func (db *Postgres) GetServicesDistinctValues(fieldName, queryFragment string, f
return nil, errors.Errorf("field name %q is not valid for filtering, valid values are %v", fieldName, validFilterFields)
}

columnName := pg.QuoteIdentifier(columnNameForField(fieldName))
columnName := pq.QuoteIdentifier(columnNameForField(fieldName))
queryFirst := fmt.Sprintf("SELECT DISTINCT %[1]s from service_full AS t WHERE t.%[1]s ILIKE $1 ",
columnName,
)
Expand Down
20 changes: 14 additions & 6 deletions components/automate-cli/pkg/diagnostics/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (c *testContext) DoLBRequest(path string, opts ...lbrequest.Opts) (*http.Re
lastErr = err
continue
}
if resp.StatusCode >= 500 {
if resp.StatusCode >= 500 || resp.StatusCode == 403 {
lastErr = errors.Errorf("Got 5xx. %d %s: %s", resp.StatusCode, resp.Status, path)
resp.Body.Close() // nolint: errcheck
continue
Expand Down Expand Up @@ -318,20 +318,28 @@ func (c *testContext) PublishViaNATS(messages [][]byte) error {
}

func (c *testContext) adminToken() (string, error) {
if c.Globals.CachedToken != "" {
return c.Globals.CachedToken, nil
}

if c.dsClient == nil {
return "", ErrDeploymentServiceUnavailable
}

if c.Globals.CachedToken == "" {
resp, err := c.dsClient.GenerateAdminToken(context.TODO(), &api.GenerateAdminTokenRequest{
var err error
var resp *api.GenerateAdminTokenResponse

for tries := 0; tries < 3; tries++ {
time.Sleep(time.Duration(tries) * time.Second)
resp, err = c.dsClient.GenerateAdminToken(context.TODO(), &api.GenerateAdminTokenRequest{
Description: "This token was generated by the chef-automate diagnostic tool. " +
"It has admin level access on the entire Automate API.",
})

if err != nil {
return "", err
if err == nil {
c.Globals.CachedToken = resp.ApiToken
break
}
c.Globals.CachedToken = resp.ApiToken
}

return c.Globals.CachedToken, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ func CreateCfgmgmtActionsDiagnostic() diagnostics.Diagnostic {
return err
}

save.CreatedEntities = append(save.CreatedEntities, cfgmgmtActionsEntity{
e := cfgmgmtActionsEntity{
EntityName: entityName,
RecordedAtMillis: day.UnixNano() / int64(time.Millisecond),
})
}
save.CreatedEntities = append(save.CreatedEntities, e)

tstCtx.SetValue("cfgmgmt-actions", save)

resp, err := tstCtx.DoLBRequest(
"/api/v0/events/data-collector",
"/api/v0/events/data-collector?z=cfgmgmt-actions",
lbrequest.WithMethod("POST"),
lbrequest.WithJSONBody(buf.String()),
)
Expand All @@ -103,7 +104,7 @@ func CreateCfgmgmtActionsDiagnostic() diagnostics.Diagnostic {
_ = resp.Body.Close()
}()
if resp.StatusCode != 200 {
return errors.Wrapf(err, "Failed to POST /api/v0/events/data-collector: Body:\n%s", buf.String())
return errors.Errorf("Failed to POST /api/v0/events/data-collector: Body:\n%s", buf.String())
}
}

Expand All @@ -125,6 +126,15 @@ func CreateCfgmgmtActionsDiagnostic() diagnostics.Diagnostic {
for _, entity := range loaded.CreatedEntities {
reqPath := fmt.Sprintf("/api/v0/eventfeed?collapse=true&page_size=100&start=%d&end=%d", entity.RecordedAtMillis-1, entity.RecordedAtMillis+1)
found := false

type eventsFeedResp struct {
Events []struct {
EntityName string `json:"entity_name"`
} `json:"events"`
}

respUnmarshalled := eventsFeedResp{}

RETRY_LOOP:
for {
resp, err := tstCtx.DoLBRequest(reqPath)
Expand All @@ -137,13 +147,7 @@ func CreateCfgmgmtActionsDiagnostic() diagnostics.Diagnostic {
// We wont retry a flakey backend. It should always return 200
require.Equal(tstCtx, 200, resp.StatusCode, "Failed to GET %s", reqPath)

type eventsFeedResp struct {
Events []struct {
EntityName string `json:"entity_name"`
} `json:"events"`
}

respUnmarshalled := eventsFeedResp{}
respUnmarshalled = eventsFeedResp{}
err = json.NewDecoder(resp.Body).Decode(&respUnmarshalled)
// We should always get valid json
require.NoError(tstCtx, err, "Failed to decode body of GET %s", reqPath)
Expand All @@ -158,9 +162,9 @@ func CreateCfgmgmtActionsDiagnostic() diagnostics.Diagnostic {
if tries >= maxTries {
break RETRY_LOOP
}
time.Sleep(2 * time.Duration(tries) * time.Second)
time.Sleep(5 * time.Duration(tries) * time.Second)
}
assert.True(tstCtx, found, "Could not find entity %s in GET %s", entity.EntityName, reqPath)
assert.True(tstCtx, found, "[%s] Could not find entity %s in GET %s; did get %+v", time.Now().UTC().String(), entity.EntityName, reqPath, respUnmarshalled)
}

},
Expand Down
2 changes: 1 addition & 1 deletion components/automate-pg-gateway/habitat/config/haproxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults
# how long a long-lived connection is allowed to stayl idle. We
# likely want to keep this high to avoid unnecessarily killing
# long-lived SQL connections used by low-request-rate services.
timeout tunnel 300s
timeout tunnel {{cfg.timeouts.idle}}s
# Client inactivity connections for half-closed connections (i.e
# the server has closed the connection and but the client has
# not). The HAProxy documentation recommends setting this whenever
Expand Down
2 changes: 2 additions & 0 deletions components/automate-pg-gateway/habitat/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ status_port = 10146

[timeouts]
connect = 5
# 12 hours
idle = 43200
Copy link
Contributor

Choose a reason for hiding this comment

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

should we wire this up to the config so its easy to change

15 changes: 9 additions & 6 deletions components/ingest-service/pipeline/message/chef_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ func (chefAction ChefAction) FinishProcessing(err error) {
if err == nil {
// Adding new metric; Time for a message to go through the pipeline
log.WithFields(log.Fields{
"message_id": chefAction.ID,
"message": "ChefAction",
"metric": "pipeline",
"type": "ingest_time",
"ms": chefAction.ClockProcessingTime(),
}).Info("Message ingested successfully")
"message_id": chefAction.ID,
"message": "ChefAction",
"metric": "pipeline",
"type": "ingest_time",
"ms": chefAction.ClockProcessingTime(),
"entity_name": chefAction.InternalChefAction.EntityName,
"entity_type": chefAction.InternalChefAction.EntityType,
"entity_task": chefAction.InternalChefAction.Task,
}).Info("Chef Action message ingested successfully")
}
}

Expand Down
8 changes: 8 additions & 0 deletions components/ingest-service/pipeline/publisher/chef_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func ChefAction(in <-chan message.ChefAction, client backend.Client, out chan<-

err := client.InsertAction(msg.Ctx, msg.InternalChefAction)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"publisher_id": number,
"message_id": msg.ID,
"buffer_size": len(out),
"entity_name": msg.InternalChefAction.EntityName,
"entity_type": msg.InternalChefAction.EntityType,
"entity_task": msg.InternalChefAction.Task,
}).Error("Failed to insert Chef Action")
msg.FinishProcessing(status.Errorf(codes.Internal, err.Error()))
} else {
out <- msg
Expand Down
4 changes: 2 additions & 2 deletions components/ingest-service/server/chef.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *ChefIngestServer) ProcessChefRun(ctx context.Context, run *chef.Run) (*
err = <-errc

if err != nil {
log.WithError(err).Error("Message failure")
log.WithError(err).Error("Chef run ingestion failure")
}
} else if run.GetMessageType() == "run_start" {
log.WithFields(log.Fields{
Expand Down Expand Up @@ -95,7 +95,7 @@ func (s *ChefIngestServer) ProcessChefAction(ctx context.Context, action *chef.A
err := <-errc

if err != nil {
log.WithError(err).Error("Message failure")
log.WithError(err).Error("Chef Action ingestion failure")
}
return &response.ProcessChefActionResponse{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion components/pg-sidecar-service/integration/pg_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/gofrs/uuid"
"github.com/lib/pq"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -578,7 +579,7 @@ SELECT EXISTS
)
;`

return c.BoolQuery(fmt.Sprintf(tableOwnedByQuery, pg.QuoteLiteral(role), pg.QuoteLiteral(table)))
return c.BoolQuery(fmt.Sprintf(tableOwnedByQuery, pq.QuoteLiteral(role), pq.QuoteLiteral(table)))
}

func (h *pgHelper) hasSuperuser(role string) (bool, error) {
Expand Down
6 changes: 3 additions & 3 deletions components/pg-sidecar-service/pkg/pgw/alter_role_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/chef/automate/lib/platform/pg"
"github.com/lib/pq"
)

// AlterRoleQuery represents the available options for an ALTER ROLE query
Expand Down Expand Up @@ -94,12 +94,12 @@ func (o *AlterRoleQuery) String() string {
if o.Password.Unencrypted {
options = append(options, "UNENCRYPTED")
}
options = append(options, fmt.Sprintf("PASSWORD %s", pg.QuoteLiteral(o.Password.Value)))
options = append(options, fmt.Sprintf("PASSWORD %s", pq.QuoteLiteral(o.Password.Value)))
}

if len(options) == 0 {
return ""
}

return fmt.Sprintf("ALTER ROLE %s WITH %s", pg.QuoteIdentifier(o.Role), strings.Join(options, " "))
return fmt.Sprintf("ALTER ROLE %s WITH %s", pq.QuoteIdentifier(o.Role), strings.Join(options, " "))
}
Loading