Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* BUGFIX: Added cancel method to fix context leak (#4767)

Signed-off-by: fazledyn-or <ataf@openrefactory.com>

* Define piped pluggin api (#4815)

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Update BuldPlan API for piped pluggin (#4821)

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Relocate plugin proto (#4826)

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Update controller to use new planner logic (#4825)

* Update controller to use new planner logic

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Update proto path

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Fix typo

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Fix typo

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Update planner logic to call proto instead of self executing

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

---------

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>

* Update plugin proto for ExecutorService and add piped pluginservice (#4834)

* Add plugin planner for k8s (#4819)

* [WIP] Add planner

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Not to use out.Version

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Use last_successful_commit_hash and last_successful_config_file_name

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Use in.WorkingDir

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Use in.PipedConfig

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Create git client

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Create secret encryptor

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add startup server implementation

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Fix for relocation of proto api

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add roughly implementation for planner plugin

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Rename pkg name

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add licence

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Comment out for the testing code

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

---------

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Truncate `deploymentStatus` metrics after reporting stats (#4857)

* Truncate deploymentStatus metrics after reporting to avoid excess message size

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

* Rename func to Flush() for clarity

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

* Add comment of what's included in statsreporter's body

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

* Fix indent in the comment

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

* Copy change of metrics.go to pipedv1

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

* Copy change of reporter.go to pipedv1

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

---------

Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>

---------

Signed-off-by: fazledyn-or <ataf@openrefactory.com>
Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Co-authored-by: Ataf Fazledin Ahamed <ataf@openrefactory.com>
Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
Co-authored-by: Yoshiki Fujikane <40124947+ffjlabo@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 8, 2024
1 parent 49627aa commit e57ade1
Show file tree
Hide file tree
Showing 297 changed files with 49,667 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ run/piped: CONFIG_FILE ?=
run/piped: INSECURE ?= false
run/piped: LAUNCHER ?= false
run/piped: LOG_ENCODING ?= humanize
run/piped: EXPERIMENTAL ?= false
run/piped:
ifeq ($(LAUNCHER),true)
ifeq ($(EXPERIMENTAL), true)
go run cmd/pipedv1/main.go piped --tools-dir=/tmp/piped-bin --config-file=$(CONFIG_FILE) --insecure=$(INSECURE) --log-encoding=$(LOG_ENCODING)
else ifeq ($(LAUNCHER),true)
go run cmd/launcher/main.go launcher --config-file=$(CONFIG_FILE) --insecure=$(INSECURE) --log-encoding=$(LOG_ENCODING)
else
go run cmd/piped/main.go piped --tools-dir=/tmp/piped-bin --config-file=$(CONFIG_FILE) --insecure=$(INSECURE) --log-encoding=$(LOG_ENCODING)
Expand Down
3 changes: 2 additions & 1 deletion cmd/pipecd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ func runHTTPServer(ctx context.Context, httpServer *http.Server, gracePeriod tim

<-ctx.Done()

ctx, _ = context.WithTimeout(context.Background(), gracePeriod)
ctx, cancel = context.WithTimeout(context.Background(), gracePeriod)
defer cancel()
logger.Info("stopping http server")
if err := httpServer.Shutdown(ctx); err != nil {
logger.Error("failed to shutdown http server", zap.Error(err))
Expand Down
35 changes: 35 additions & 0 deletions cmd/pipedv1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"log"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/cmd/piped"
"github.com/pipe-cd/pipecd/pkg/cli"
)

func main() {
app := cli.NewApp(
"piped",
"A component that runs inside target environment to execute deployment and report its state.",
)
app.AddCommands(
piped.NewCommand(),
)
if err := app.Run(); err != nil {
log.Fatal(err)
}
}
5 changes: 5 additions & 0 deletions pkg/app/piped/controller/controllermetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ func Register(r prometheus.Registerer) {
deploymentStatus,
)
}

// Flush deletes all deploymentStatus metrics to remove old unnecessary metrics.
func Flush() {
deploymentStatus.Reset()
}
14 changes: 14 additions & 0 deletions pkg/app/piped/statsreporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/pipe-cd/pipecd/pkg/app/piped/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
)

Expand Down Expand Up @@ -92,11 +93,24 @@ func (r *reporter) report(ctx context.Context) error {
}

req := &pipedservice.ReportStatRequest{
// PipedStats includes the following metrics in addition to Go metrics:
// - cloudprovider_kubernetes_tool_calls_total
// - deployment_status
// - livestatestore_kubernetes_api_requests_total
// - livestatestore_kubernetes_resource_events_total
// - plan_preview_command_handled_total
// - plan_preview_command_handling_seconds
// - plan_preview_command_received_total
PipedStats: b,
}
if _, err := r.apiClient.ReportStat(ctx, req); err != nil {
r.logger.Error("failed to report stats", zap.Error(err))
return err
}

// Delete deployment metrics which are already reported
// in order to avoid error of excess message size.
controllermetrics.Flush()

return nil
}
80 changes: 80 additions & 0 deletions pkg/app/pipedv1/analysisprovider/http/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package http provides a way to analyze with http requests.
// This allows you to do smoke tests, load tests and so on, at your leisure.
package http

import (
"context"
"fmt"
"net/http"
"time"

"github.com/pipe-cd/pipecd/pkg/config"
)

const (
ProviderType = "HTTP"
defaultTimeout = 30 * time.Second
)

type Provider struct {
client *http.Client
}

func (p *Provider) Type() string {
return ProviderType
}

func NewProvider(timeout time.Duration) *Provider {
if timeout == 0 {
timeout = defaultTimeout
}
return &Provider{
client: &http.Client{Timeout: timeout},
}
}

// Run sends an HTTP request and then evaluate whether the response is expected one.
func (p *Provider) Run(ctx context.Context, cfg *config.AnalysisHTTP) (bool, string, error) {
req, err := p.makeRequest(ctx, cfg)
if err != nil {
return false, "", err
}

res, err := p.client.Do(req)
if err != nil {
return false, "", err
}
defer res.Body.Close()

if res.StatusCode != cfg.ExpectedCode {
return false, "", fmt.Errorf("unexpected status code %d", res.StatusCode)
}
// TODO: Decide how to check if the body is expected one.
return true, "", nil
}

func (p *Provider) makeRequest(ctx context.Context, cfg *config.AnalysisHTTP) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, cfg.Method, cfg.URL, nil)
if err != nil {
return nil, err
}
req.Header = make(http.Header, len(cfg.Headers))
for _, h := range cfg.Headers {
req.Header.Set(h.Key, h.Value)
}
return req, nil
}
47 changes: 47 additions & 0 deletions pkg/app/pipedv1/analysisprovider/log/factory/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package factory

import (
"fmt"
"os"

"go.uber.org/zap"

"github.com/pipe-cd/pipecd/pkg/app/piped/analysisprovider/log"
"github.com/pipe-cd/pipecd/pkg/app/piped/analysisprovider/log/stackdriver"
"github.com/pipe-cd/pipecd/pkg/config"
"github.com/pipe-cd/pipecd/pkg/model"
)

// NewProvider generates an appropriate provider according to analysis provider config.
func NewProvider(providerCfg *config.PipedAnalysisProvider, logger *zap.Logger) (provider log.Provider, err error) {
switch providerCfg.Type {
case model.AnalysisProviderStackdriver:
cfg := providerCfg.StackdriverConfig
sa, err := os.ReadFile(cfg.ServiceAccountFile)
if err != nil {
return nil, err
}
provider, err = stackdriver.NewProvider(sa)
if err != nil {
return nil, err
}

default:
return nil, fmt.Errorf("any of providers config not found")
}
return provider, nil
}
28 changes: 28 additions & 0 deletions pkg/app/pipedv1/analysisprovider/log/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package log

import (
"context"
)

// Provider represents a client for log provider which provides logs for analysis.
type Provider interface {
Type() string
// Evaluate runs the given query against the log provider,
// and then checks if there is at least one error log.
// Returns the result reason if non-error occurred.
Evaluate(ctx context.Context, query string) (result bool, reason string, err error)
}
43 changes: 43 additions & 0 deletions pkg/app/pipedv1/analysisprovider/log/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stackdriver

import (
"context"
"time"
)

const ProviderType = "StackdriverLogging"

// Provider is a client for stackdriver.
type Provider struct {
serviceAccount []byte

timeout time.Duration
}

func NewProvider(serviceAccount []byte) (*Provider, error) {
return &Provider{
serviceAccount: serviceAccount,
}, nil
}

func (p *Provider) Type() string {
return ProviderType
}

func (p *Provider) Evaluate(ctx context.Context, query string) (bool, string, error) {
return false, "", nil
}
Loading

0 comments on commit e57ade1

Please sign in to comment.