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

Backport CORE-1123 to Pachyderm 2.3 #8283

Merged
merged 1 commit into from
Oct 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc/docs/2.3.x/deploy-manage/deploy/loki.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ loki-stack:

![Container logs](../images/grafana_user_logs.png)


## Using Loki in Another Namespace
Instead of deploying a local loki instance in your pachyderm namespace, you can configure pachyderm to use a loki running in another namespace. To do so, you must
set `lokiHost` and `lokiPort`. You should also set `lokiDeploy: false` to prevent the chart from deploying a local loki instance.:
```yaml
pachd:
lokiDeploy: false
lokiHost: "<loki-namespace>.<loki-service-name>.svc.cluster.local."
lokiPort: 3100
```

## References

Expand Down
10 changes: 9 additions & 1 deletion doc/docs/master/deploy-manage/deploy/loki.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ loki-stack:

![Container logs](../images/grafana_user_logs.png)


## Using Loki in Another Namespace
Instead of deploying a local loki instance in your pachyderm namespace, you can configure pachyderm to use a loki running in another namespace. To do so, you must
set `lokiHost` and `lokiPort`. You should also set `lokiDeploy: false` to prevent the chart from deploying a local loki instance.:
```yaml
pachd:
lokiDeploy: false
lokiHost: "<loki-namespace>.<loki-service-name>.svc.cluster.local."
lokiPort: 3100
```

## References

Expand Down
16 changes: 11 additions & 5 deletions etc/helm/pachyderm/templates/pachd/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ spec:
value: "5432" # Must match pbouncer service port
- name: LOKI_LOGGING
value: {{ .Values.pachd.lokiLogging | quote}}
{{- if .Values.pachd.lokiDeploy }}
- name: LOKI_SERVICE_HOST_VAR
value: "{{ snakecase .Release.Name | upper }}_LOKI_SERVICE_HOST"
- name: LOKI_SERVICE_PORT_VAR
value: "{{ snakecase .Release.Name | upper }}_LOKI_SERVICE_PORT"
- name: LOKI_SERVICE_HOST
{{- if .Values.pachd.lokiHost }}
value: {{ .Values.pachd.lokiHost }}
{{ else }}
value: "$({{ snakecase .Release.Name | upper }}_LOKI_SERVICE_HOST)"
{{- end }}
- name: LOKI_SERVICE_PORT
{{- if .Values.pachd.lokiPort }}
value: {{ .Values.pachd.lokiPort | quote}}
{{ else }}
value: "$({{ snakecase .Release.Name | upper }}_LOKI_SERVICE_PORT)"
{{- end }}
- name: PACH_ROOT
value: "/pach"
Expand Down
6 changes: 6 additions & 0 deletions etc/helm/pachyderm/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@
"lokiLogging": {
"type": "boolean"
},
"lokiPort": {
"type": "integer"
},
"lokiHost": {
"type": "string"
},
"metrics": {
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/serviceenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type GlobalConfiguration struct {
Namespace string `env:"PACH_NAMESPACE,default=default"`
StorageRoot string `env:"PACH_ROOT,default=/pach"`
GCPercent int `env:"GC_PERCENT,default=50"`
LokiHostVar string `env:"LOKI_SERVICE_HOST_VAR,default=LOKI_SERVICE_HOST"`
LokiPortVar string `env:"LOKI_SERVICE_PORT_VAR,default=LOKI_SERVICE_PORT"`
LokiHost string `env:"LOKI_SERVICE_HOST"`
LokiPort string `env:"LOKI_SERVICE_PORT"`
OidcPort uint16 `env:"OIDC_PORT,default=1657"`
PGBouncerHost string `env:"PG_BOUNCER_HOST,required"`
PGBouncerPort int `env:"PG_BOUNCER_PORT,required"`
Expand Down
2 changes: 1 addition & 1 deletion src/internal/serviceenv/service_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func InitServiceEnv(config *Configuration) *NonblockingServiceEnv {
env.dbEg.Go(env.initDirectDBClient)
}
env.listener = env.newListener()
if lokiHost, lokiPort := os.Getenv(env.config.LokiHostVar), os.Getenv(env.config.LokiPortVar); lokiHost != "" && lokiPort != "" {
if lokiHost, lokiPort := env.config.LokiHost, env.config.LokiPort; lokiHost != "" && lokiPort != "" {
env.lokiClient = &loki.Client{
Address: fmt.Sprintf("http://%s", net.JoinHostPort(lokiHost, lokiPort)),
}
Expand Down
5 changes: 3 additions & 2 deletions src/server/debug/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/types"

"github.com/pachyderm/pachyderm/v2/src/client"
"github.com/pachyderm/pachyderm/v2/src/debug"
"github.com/pachyderm/pachyderm/v2/src/internal/clientsdk"
Expand Down Expand Up @@ -709,7 +710,7 @@ func (s *debugServer) collectLogs(ctx context.Context, tw *tar.Writer, pod, cont
}

func (s *debugServer) collectLogsLoki(ctx context.Context, tw *tar.Writer, pod, container string, prefix ...string) error {
if os.Getenv(s.env.Config().LokiHostVar) == "" {
if s.env.Config().LokiHost == "" {
return nil
}
return collectDebugFile(tw, "logs-loki", "txt", func(w io.Writer) error {
Expand Down Expand Up @@ -774,7 +775,7 @@ func (s *debugServer) collectPipelineDumpFunc(limit int64) collectPipelineFunc {
if err := s.collectJobs(tw, pachClient, pipelineInfo.Pipeline.Name, limit, prefix...); err != nil {
return err
}
if os.Getenv(s.env.Config().LokiHostVar) != "" {
if s.env.Config().LokiHost != "" {
if err := s.forEachWorkerLoki(ctx, pipelineInfo, func(pod string) error {
workerPrefix := join(podPrefix, pod)
if len(prefix) > 0 {
Expand Down
21 changes: 11 additions & 10 deletions src/server/pps/server/worker_rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import (
"strings"

jsonpatch "github.com/evanphx/json-patch"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"

client "github.com/pachyderm/pachyderm/v2/src/client"
"github.com/pachyderm/pachyderm/v2/src/internal/config"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
Expand All @@ -19,12 +26,6 @@ import (
"github.com/pachyderm/pachyderm/v2/src/pps"
workerstats "github.com/pachyderm/pachyderm/v2/src/server/worker/stats"
"github.com/pachyderm/pachyderm/v2/src/version"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)

const (
Expand Down Expand Up @@ -150,11 +151,11 @@ func (kd *kubeDriver) workerPodSpec(options *workerOptions, pipelineInfo *pps.Pi
Name: client.PPSPipelineNameEnv,
Value: pipelineInfo.Pipeline.Name,
}, {
Name: "LOKI_SERVICE_HOST_VAR",
Value: kd.config.LokiHostVar,
Name: "LOKI_SERVICE_HOST",
Value: kd.config.LokiHost,
}, {
Name: "LOKI_SERVICE_PORT_VAR",
Value: kd.config.LokiPortVar,
Name: "LOKI_SERVICE_PORT",
Value: kd.config.LokiPort,
},
// These are set explicitly below to prevent kubernetes from setting them to the service host and port.
{
Expand Down